scooterw / ffi-ogr

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

Support for reading from a GeoServices FeatureService and converting to GeoJSON #1

Closed ajturner closed 10 years ago

ajturner commented 11 years ago

It would be nice to use the fast OGR library to convert GeoServices JSON to GeoJSON.

Essentially bindings to support: http://gis.stackexchange.com/questions/13029/how-to-convert-arcgis-server-json-to-geojson

scooterw commented 11 years ago

Check out the new feature_service branch.

Example usage:

fs = OGR::FeatureServiceReader.new.read 'http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/0/query?where=objectid+%3D+objectid&outfields=*&f=json'
fs.to_json # will output as geojson string fs.to_geojson(file_path) to output to file

This branch also has a new way to list all available drivers: OGR.drivers (alias of OGR.get_available_drivers)

Let me know if this is along the lines of what you are thinking.

BTW. I accidentally hit the close issue button, but If have reopened it.

ajturner commented 11 years ago

this looks good - though why the two versions of the function? Perhaps just to_geojson with an optional parameter. WIth a filename writes the file otherwise return the string?

scooterw commented 11 years ago

This makes a lot of sense. I need to give some love to the API in general, and will give this some thought.

ajturner commented 11 years ago

Cool. I think extending to support more of the output drivers would be great as well. Particularly KML and SQLite.

scooterw commented 11 years ago

There is a way to do this currently, but it, like the rest of this, is not documented.

kml_reader = OGR::GenericReader.new 'KML'
data = kml_reader.read '/path/to/your/kml_file.kml'

I would have handled the FeatureService in this way, but it needed some additional work that made it make more sense to move it to its own class. That said, I will likely move to a OGR::KMLReader class in order to handle things like unzipping .kmz files to make the library behave with .kmz files.

Multi-layer KML files seem to have issues with geojson output. This will need to be examined.

To list available drivers (available in feature_service branch; master soon):

OGR.drivers
=> ["ESRI Shapefile", "MapInfo File", "UK .NTF", "SDTS", "TIGER", "S57", "DGN", "VRT", "REC", "Memory", "BNA", "CSV", "NAS", "GML", "GPX", "KML", "GeoJSON", "Interlis 1", "Interlis 2", "GMT", "SQLite", "DODS", "ODBC", "PGeo", "MSSQLSpatial", "PostgreSQL", "PCIDSK", "FileGDB", "XPlane", "AVCBin", "AVCE00", "DXF", "Geoconcept", "GeoRSS", "GPSTrackMaker", "VFK", "PGDump", "OSM", "GPSBabel", "SUA", "OpenAir", "PDS", "WFS", "HTF", "AeronavFAA", "Geomedia", "EDIGEO", "GFT", "SVG", "CouchDB", "Idrisi", "ARCGEN", "SEGUKOOA", "SEGY", "XLS", "ODS", "XLSX", "ElasticSearch", "PDF"]

My plan is to work this into something like:

data = OGR.read '/path/to/my_data.kml'

The read method would have access to some sort of hash or something that will link known extensions to driver type and call it appropriately.

scooterw commented 10 years ago

@ajturner Can I close this given the recent changes and your merged PR?