How to convert shapefile coordinates?

I am trying to get neighborhood data in my application, and I am having problems with the data that I use, which I got from here .

This file contains a shapefile in which there are neighborhoods in San Francisco. I am using the Ruby on Rails framework, and now I am using GeoRuby to parse the shapefile.

The code is as follows:

def self.run_import shpfile = '/path/to/realtor_neighborhoods/realtor_neighborhoods' ShpFile.open(shpfile) do |shp| shp.each do |shape| # This gets the first (and only) Polygon from each MultiPolygon polygon = shape.geometry.geometries.first puts polygon.inspect end end end 

The code is able to parse the file, but I cannot understand the coordinates as interpreted. All points matter in millions when I expect coordinates between -180 and 180, for actual latitude and longitude. Take a look at an example example:

 <GeoRuby::SimpleFeatures::Point:0x00000104566a08 @srid=4326, @with_z=false, \ @with_m=false, @x=6015402.9999795845, @y=2114960.4999904726, @z=0.0, @m=0.0>, 

What is the format of these coordinate values? How can I convert them to values ​​that matter to me? (i.e. latitude / longitude based on the spatial system SRID 4326 <=> WGS84)

Thank you in advance!

+8
ruby ruby-on-rails gis postgis shapefile
source share
4 answers

Data obtained from the form file, projected geographic data .

From your question, it sounds as if you simply prefer to have your data in lat / long format. To do this, you need to reprogram your data. I am not a ruby ​​guy, but a quick web search shows that georuby does not support repeat playback of http://georuby.rubyforge.org/ , however rgeo . http://www.daniel-azuma.com/blog/archives/28

If you want to know more about map projections, look here .

By the way, there is a stackexchange site for GIS experts (geographic information systems) called http://gis.stackexchange.com

+6
source share

I noticed that the view log is still getting. I ended up fighting RGeo, but there was a different solution. If you are able / want to do your conversion outside / before executing your ruby ​​code, check ogr2ogr.

There is more detailed information in my comment below: How to use (Ruby) RGeo to convert (Unproject) coordinates

+1
source share

I came across this question, because I wanted to convert the points provided in the Shapefile from the British national grid format OSGB36 to WGS84 (decimal degrees). I spent a lot of time on this, so hopefully this code will prove to be useful.

This code uses the ffi-ogr gem and requires GDAL :

 require 'ffi-ogr' data = OGR.read file_name new_spatial_ref = OGR.import_sr(4326, 'epsg') data.layers.each do |layer| transformer = OGR::CoordinateTransformation.find_transformation(layer.spatial_ref, new_spatial_ref) layer.features.each do |feature| geometry = OGR::Tools.cast_geometry(feature.geometry) geometry.transform(transformer) # Do something with geometry here end end 
0
source share

I had the same problem: I wanted to convert the projected geodata to Lat / Long values.

The ogr2ogr tool was much easier to use than I expected.

For installation:

apt-get install gdal-bin

Get information about your shapefile:

ogrinfo data.shp -al -so

Convert to Lat / Long and JSON:

ogr2ogr -f GeoJSON -t_srs WGS84 data.json data.shp

0
source share

All Articles