ruby - How can I read WKT from the shapefile .prj? -
i building system lets users upload shapefiles. converts shapefiles postgis using shp2pgsql
. command requires srs id in form of epsg code.
so need ruby gem can read shapefile's *.prj
file (which contains projection/spatial reference system encoded wkt) , return corresponding srs id.
i'm not sure how ruby bindings work gdal, osr (part of gdal) can extract either projection wkt (text) or srid (integer).
see this gis.se answer solution python/gdal/osr.
update: turns out ruby bindings work nicely expected. going, try code:
require 'gdal/osr' prj_fname = 'myfile.prj' prj = file.open( prj_fname ) # import wkt prj file srs = gdal::osr::spatialreference.new() srs.import_from_wkt( prj.read ) # various exports puts srs.export_to_wkt srs.auto_identify_epsg puts srs.get_authority_name(nil) puts srs.get_authority_code(nil)
if need other aspect of projection, explore available public methods:
srs.public_methods.sort
Comments
Post a Comment