scooterw / ffi-ogr

Convenient Ruby wrapper for OGR
MIT License
13 stars 5 forks source link

KML output only reprojects longitude #7

Open ajturner opened 10 years ago

ajturner commented 10 years ago

For some reason, the KML output doesn't seem to reproject Latitude.

Also, GeoJSON isn't re-projected at all.

Is this an issue with OGR or with my install or something else?

scooterw commented 10 years ago

I've looked into this issue a bit, and am finding some interesting behaviors. I was not properly reading the spatial_ref hash in OGR::DataSource#to_format. This has been addressed in 35ca0b5. GeoJSON and SHP seem to reproject as expected. CSV appears to be broken, but that is another issue entirely, and will be investigated on a separate ticket.

KML output should not be reprojected per the OGR documentation. According to the doc at http://www.gdal.org/ogr/drv_kml.html : "KML by specification uses only a single projection, EPSG:4326. All OGR KML output will be presented in EPSG:4326. As such OGR will create layers in the correct coordinate system and transform any geometries." I'm not observing any reprojection, which would seem to agree with the docs. If you are seeing other results, please let me know what version of GDAL you are working with, and any other pertinent details about your particular setup and I will try to take a look. I am running 1.10.1 (installed with Homebrew) on OS X 10.8.5 if that helps you at all.

I will leave this issue open for the time being in case further discussion is needed on either the GeoJSON reprojection that was addressed in investigating the KML issue, or issues surrounding KML. In the meantime, I will be modifying OGR::DataSource#to_kml to issue a warning that the output will not be reprojected if a projection is passed in.

scooterw commented 10 years ago

Closing

ajturner commented 10 years ago

by the way - this is related to #4. It appears that you need to pass in the s_srs and then latitude is 'projected' correctly to EPSG:4326

scooterw commented 10 years ago

Thank you for bringing this to my attention. I did not see this before. I will make sure this works with the work being done to allow for passing options to drivers in #4 . I am reopening this issue for tracking and discussion.

ajturner commented 10 years ago

Specific to this issue - if I do

ogr2ogr -s_srs "EPSG:3857" -t_srs "EPSG:4326" -f KML output.kml MyData.shp

then it works fine. If I omit s_srs then it doesn't work. So the question is how to pass the Source SRS in the driver call. Diving through the GDAL code it's not clear if this is in the CopyDriver as SRC_SRS

scooterw commented 10 years ago

@ajturner Please verify that this works for you. The LIBKML driver allows for reprojection while the KML driver does not. The changes in b923934 use LIBKML when available. When calling DataSource#to_kml, a warning will be output indicating that the KML driver is being used because LIBKML is not available, and as a result all output will be in EPSG:4326.