Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I transform the coordinates of a Shapefile?

I am trying to get neighborhood data into my application, and I'm having problems with the data I am using, which I got from here.

This file contains a shapefile that has the neighborhoods of San Francisco. I am running a Ruby on Rails framework, and I'm currently using GeoRuby to parse the shapefile.

The code looks like this:

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 am unable to understand the coordinates as interpreted. All of the points have values in the millions, when I would expect coordinates between -180 and 180, for valid latitude and longitude. Take a look at an example point:

<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 are meaningful to me? (i.e. latitude/longitude based on the SRID 4326 <=> WGS84 spatial reference system)

Thank you in advance!

like image 415
Larry Avatar asked Aug 06 '11 00:08

Larry


People also ask

Do shapefiles have a coordinate system?

A shapefile often doesn't have any information that identifies which coordinate system was used to define its features. In this case, the Shape column's Spatial Reference property will be Unknown or Assumed Geographic.


2 Answers

The data you have from the shape file is projected geographic data.

From your question it sounds like you would really just prefer to have your data in lat/long. To get that you need to reproject your data. I am not a ruby guy, but a quick web search reveals that georuby does not support reprojection http://georuby.rubyforge.org/, however rgeo does. http://www.daniel-azuma.com/blog/archives/28

If you would like to know more about map projections have a look here.

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

like image 73
steenhulthin Avatar answered Oct 19 '22 22:10

steenhulthin


I noticed this is still getting a log of views. I ended up struggling with RGeo, but there's another solution. If you are able/willing to do your conversion outside/before you execute your ruby code, check out ogr2ogr.

There are more details in my comment on the bottom here: How Can I Use (Ruby) RGeo to Transform (Unproject) Coordinates

like image 43
Larry Avatar answered Oct 20 '22 00:10

Larry