Convert svg to geojson fails with ogr2ogr

夙愿已清 提交于 2019-12-12 13:25:02

问题


I've downloaded an .svg map of Finland from http://www.amcharts.com/svg-maps/?map=finland

I want to convert it to topojson to use it with d3.js. I first start with svg to geojson conversion, but it fails.

I tried:

ogr2ogr -f "GeoJSON" finland_kunta.json finlandHigh.svg 

The error I get:

FAILURE:
Unable to open datasource `finlandHigh.svg' with the following drivers.
  -> ESRI Shapefile
  -> MapInfo File
  -> UK .NTF
  -> SDTS
  -> TIGER
  -> S57
  -> DGN
  -> VRT
  -> REC
  -> Memory
  -> BNA
  -> CSV
  -> GML
  -> GPX
  -> KML
  -> GeoJSON
  -> GMT
  -> GPKG
  -> SQLite
  -> WAsP
  -> PCIDSK
  -> OpenFileGDB
  -> XPlane
  -> AVCBin
  -> AVCE00
  -> DXF
  -> Geoconcept
  -> GeoRSS
  -> GPSTrackMaker
  -> VFK
  -> PGDump
  -> OSM
  -> GPSBabel
  -> SUA
  -> OpenAir
  -> PDS
  -> WFS
  -> HTF
  -> AeronavFAA
  -> EDIGEO
  -> GFT
  -> GME
  -> SVG
  -> CouchDB
  -> Idrisi
  -> ARCGEN
  -> SEGUKOOA
  -> SEGY
  -> XLS
  -> ODS
  -> XLSX
  -> ElasticSearch
  -> PDF
  -> CartoDB
  -> SXF

I'm only starting to figure these tools out, so I'm not sure what exactly causes the error. When I open svg, it seems to look fine and have all the elements.


回答1:


Actually in most cases you can use the SVG image as is, no need to convert it to topojson or GeoJSON but there are a few issues to consider:

  1. Is the original SVG file size too big for your application ? If it is then you can optimize the SVG file (For example, with: http://petercollingridge.appspot.com/svg-editor). If that's not enough then you can get a shapefile from another source (For example: http://www.naturalearthdata.com/downloads/) and convert it to GeoJSON (Use ogr2ogr, either through their web interface at http://ogre.adc4gis.com/ or you download it with GDAL at http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries). If the resulting file is still too big you can compress with mapshaper (http://www.mapshaper.org/ - it takes both shapefiles and GeoJSON formats!) and if necessary (if your file size is still an issue) convert the resulting map from GeoJSON to topojson (see: http://github.com/mbostock/topojson/wiki).

  2. Do you need to use location data in your map ? (for example, you may need to mark where a certain city is in you map but the city is not drawn on your original SVG) Then it is easier to get a shapefile and convert it to GeoJSON (using ogr2ogr) because most likely you do not have geolocation information on the downloaded SVG file.

  3. If you're creating a choropleth and have no geolocation requirements then you can simply add the SVG directy to your page and use D3 to map data to your image! Once you have the SVG in your page then you can even manually edit all path data to include classes and ids that will make your D3 job easier.



来源:https://stackoverflow.com/questions/34187024/convert-svg-to-geojson-fails-with-ogr2ogr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!