lib/postgis_functions.rb in nofxx-postgis_adapter-0.1.8 vs lib/postgis_functions.rb in nofxx-postgis_adapter-0.2.1
- old
+ new
@@ -16,27 +16,27 @@
# Earth Spheroid - http://en.wikipedia.org/wiki/Figure_of_the_Earth
#
#
#
module PostgisFunctions
- # EARTH_SPHEROID = "'SPHEROID[\"GRS-80\",6378137,298.257222101]'"
+ EARTH_SPHEROID = "'SPHEROID[\"GRS-80\",6378137,298.257222101]'" # SRID => 4326
+ #EARTH_SPHEROID = "'SPHEROID[\"IERS_2003\",6378136.6,298.25642]'" # SRID =>
- EARTH_SPHEROID = "'SPHEROID[\"IERS_2003\",6378136.6,298.25642]'"
-
def postgis_calculate(operation, subjects, options = nil)
subjects = [subjects] unless subjects.respond_to?(:map)
return execute_geometrical_calculation(operation, subjects, options)
rescue Exception => e
raise StandardError, "#{e}"
end
-
private
-
+ def get_column_name
+ @geo_column ||= postgis_geoms[:columns].first
+ end
+
# Construct the postgis sql query
- # TODO: ST_Transform() ?? # Convert between distances. Implement this?
#
# Area return in square feet
# Distance/DWithin/Length/Perimeter — in projected units.
# DistanceSphere/Spheroid — in meters.
#
@@ -47,29 +47,28 @@
:class => t.class.to_s.downcase.pluralize,
:uid => unique_identifier,
:id => t[:id] }
end
- fields = tables.map { |f| "#{f[:uid]}.geom" } # W1.geom
+ fields = tables.map { |f| "#{f[:uid]}.#{get_column_name}" } # W1.geom
conditions = tables.map { |f| "#{f[:uid]}.id = #{f[:id]}" } # W1.id = 5
tables.map! { |f| "#{f[:class]} #{f[:uid]}" } # streets W1
#
# Data => SELECT Func(A,B)
# BBox => SELECT (A <=> B)
#
- if type == :bbox
- opcode = nil
- s_join = " #{options} "
- else
+ unless type == :bbox
opcode = type.to_s
opcode = "ST_#{opcode}" unless opcode =~ /th3d|pesinter/
- s_join = ","
fields << options if options
+ fields = fields.join(",")
+ else
+ fields = fields.join(" #{options} ")
end
- sql = "SELECT #{opcode}(#{fields.join(s_join)}) "
+ sql = "SELECT #{opcode}(#{fields}) "
sql << "FROM #{tables.join(",")} " if tables
sql << "WHERE #{conditions.join(" AND ")}" if conditions
#p sql; sql
end
@@ -92,10 +91,10 @@
end
end
# Get a unique ID for tables
def unique_identifier
- @u_id ||= "W1"
+ @u_id ||= "T1"
@u_id = @u_id.succ
end
end