lib/postgis_functions/common.rb in nofxx-postgis_adapter-0.3.1 vs lib/postgis_functions/common.rb in nofxx-postgis_adapter-0.3.3

- old
+ new

@@ -377,11 +377,11 @@ # so use ST_Polygonize in conjunction with ST_Dump to dump the polygons out into # individual polygons. # # Returns Geometry ST_Polygonize(geometry set geomfield); # - def polygonize#(geom) + def polygonize postgis_calculate(:polygonize, self) end # # Returns true if this Geometry is spatially related to anotherGeometry, @@ -435,12 +435,16 @@ # # Requires PostGIS be compiled with Proj support. # # Return Geometry ST_Transform(geometry g1, integer srid); # + def transform!(new_srid) + self[get_column_name] = postgis_calculate("Transform", self, new_srid) + end + def transform(new_srid) - postgis_calculate("Transform", self, new_srid) + dup.transform!(new_srid) end # # Returns a modified geometry having no segment longer than the given distance. # Distance computation is performed in 2d only. @@ -452,10 +456,56 @@ def segmentize(max_length=1.0) postgis_calculate("segmentize", self, max_length) end # + # Returns the instance`s geom srid + # + def srid + self[get_column_name].srid + end + + # + # Return UTM Zone for a geom + # + # Return Integer + def utm_zone + if srid == 4326 + geom = centroid + else + geomdup = transform(4326) + mezzo = geomdup.length / 2 + geom = case geomdup + when Point then geomdup + when LineString then geomdup[mezzo] + else + geomgeog[mezzo][geomgeo[mezzo]/2] + end + + end + + pref = geom.y > 0 ? 32700 : 32600 + zone = ((geom.x + 180) / 6 + 1).to_i + zone + pref + end + + # + # Returns the Geometry in its UTM Zone + # + # Return Geometry + def to_utm!(utm=nil) + utm ||= utm_zone + self[get_column_name] = transform(utm) + end + + def to_utm + dup.to_utm! + end + + # + # + # # LINESTRING # # # module LineStringFunctions @@ -621,20 +671,29 @@ # postgis_calculate(:max_distance, [self, other]) #end end - #### - ### - ## # + # + # + # # POINT # # + # + # module PointFunctions # + # Some nice getters + # + def x; @x ||= self[get_column_name].x; end + def y; @y ||= self[get_column_name].y; end + def z; @z ||= self[get_column_name].z; end + + # # Returns a float between 0 and 1 representing the location of the closest point # on LineString to the given Point, as a fraction of total 2d line length. # # You can use the returned location to extract a Point (ST_Line_Interpolate_Point) # or a substring (ST_Line_Substring). @@ -708,13 +767,16 @@ postgis_calculate(:point_inside_circle, self, [x,y,r]) end end - ### - ## # + # + # + # # Polygon + # + # # # module PolygonFunctions #