使用 ogr2ogr 将 svg 转换为 geojson 失败
Convert svg to geojson fails with ogr2ogr
我从 http://www.amcharts.com/svg-maps/?map=finland
下载了芬兰的 .svg 地图
我想将它转换为 topojson 以便与 d3.js 一起使用。我首先从 svg 到 geojson 的转换开始,但它失败了。
我试过了:
ogr2ogr -f "GeoJSON" finland_kunta.json finlandHigh.svg
我得到的错误:
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
我才刚刚开始弄清楚这些工具,所以我不确定究竟是什么导致了错误。当我打开 svg 时,它看起来不错并且包含所有元素。
实际上在大多数情况下您可以直接使用 SVG 图片,无需将其转换为 topojson 或 GeoJSON,但有几个问题需要考虑:
原始 SVG 文件大小是否对您的应用程序来说太大了?如果是,那么您可以优化 SVG 文件(例如,使用: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)。
您需要在地图中使用位置数据吗? (例如,您可能需要在地图中标记某个城市的位置,但该城市并未绘制在原始 SVG 上)然后获取 shapefile 并将其转换为 GeoJSON(使用 ogr2ogr)会更容易,因为您很可能会这样做下载的 SVG 文件没有地理位置信息。
如果您正在创建等值线并且没有地理定位要求,那么您只需将 SVG 目录添加到您的页面并使用 D3 将数据映射到您的图像!一旦您的页面中有了 SVG,您甚至可以手动编辑所有路径数据以包含 类 和 id,这将使您的 D3 工作更容易。
我从 http://www.amcharts.com/svg-maps/?map=finland
下载了芬兰的 .svg 地图我想将它转换为 topojson 以便与 d3.js 一起使用。我首先从 svg 到 geojson 的转换开始,但它失败了。
我试过了:
ogr2ogr -f "GeoJSON" finland_kunta.json finlandHigh.svg
我得到的错误:
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
我才刚刚开始弄清楚这些工具,所以我不确定究竟是什么导致了错误。当我打开 svg 时,它看起来不错并且包含所有元素。
实际上在大多数情况下您可以直接使用 SVG 图片,无需将其转换为 topojson 或 GeoJSON,但有几个问题需要考虑:
原始 SVG 文件大小是否对您的应用程序来说太大了?如果是,那么您可以优化 SVG 文件(例如,使用: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)。
您需要在地图中使用位置数据吗? (例如,您可能需要在地图中标记某个城市的位置,但该城市并未绘制在原始 SVG 上)然后获取 shapefile 并将其转换为 GeoJSON(使用 ogr2ogr)会更容易,因为您很可能会这样做下载的 SVG 文件没有地理位置信息。
如果您正在创建等值线并且没有地理定位要求,那么您只需将 SVG 目录添加到您的页面并使用 D3 将数据映射到您的图像!一旦您的页面中有了 SVG,您甚至可以手动编辑所有路径数据以包含 类 和 id,这将使您的 D3 工作更容易。