我有一个代表学区的多边形,它是从NYC Open Data导入的。我相信坐标在epsg 投影 2263 - nad83 / 纽约长岛
我无法将坐标转换为谷歌地图可用的格式。
这是我从原始 shapefile 导入多边形的代码:
proj4 = "+proj=lcc +lat_1=41.03333333333333 +lat_2=40.66666666666666 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"
factory = RGeo::Geographic.projected_factory(:projection_proj4 => proj4, :projection_srid => 2263)
RGeo::Shapefile::Reader.open("/Users/dmanaster1/flatiron_school/nycdata/db/source/ES_Zones_2013-2014.shp", :factory => factory.projection_factory) do |file|
file.each do |record|
school_zone = ES_Zone.new
...
school_zone.geometry = record.geometry
school_zone.save
end
file.rewind
end
在我的模型中:
class ES_Zone < ActiveRecord::Base
proj4 = "+proj=lcc +lat_1=41.03333333333333 +lat_2=40.66666666666666 +lat_0=40.16666666666666 +lon_0=-74 +x_0=300000.0000000001 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"
FACTORY = RGeo::Geographic.projected_factory(:projection_proj4 => proj4, :projection_srid => 2263)
set_rgeo_factory_for_column(:geometry, FACTORY.projection_factory)
end
在我的控制器中:
def index
polygons = format_polygon(ES_Zone.first)
gon.polygons = JSON.parse(polygons.to_json)
end
private
def format_polygon(zone)
array = Array.new
zone.geometry.each do |polygon|
polygon.exterior_ring.points.each do |point|
x = point.x
y = point.y
array << { "lng" => x, "lat" => y }
end
end
[array]
end
我知道我缺少关于如何转换坐标的一些东西,但我不确定从这里去哪里,即使在阅读了 Daniel Azuma 的优秀指南之后。有人知道怎么做吗?