使用ogr2​​ogr将svg转换为geojson失败 [英] Convert svg to geojson fails with ogr2ogr

查看:335
本文介绍了使用ogr2​​ogr将svg转换为geojson失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从 http://www下载了芬兰的.svg地图. amcharts.com/svg-maps/?map=finland

我想将其转换为topojson以与d3.js结合使用.我首先从svg到geojson转换开始,但是失败了.

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

我尝试过:

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时,看起来不错,并具有所有元素.

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.

推荐答案

实际上,在大多数情况下,您可以按原样使用SVG图像,无需将其转换为topojson或GeoJSON,但是要考虑一些问题:

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. 对于您的应用程序,原始SVG文件大小是否太大?如果是,则可以优化SVG文件(例如,使用以下命令: http://petercollingridge.appspot.com/svg-editor ).如果这还不够,那么您可以从另一个来源获取shapefile(例如: http://www.naturalearthdata.com/downloads/)并将其转换为GeoJSON(使用ogr2​​ogr,可以通过其Web界面位于 http://ogre .adc4gis.com/或使用GDAL从 http://trac.osgeo下载.org/gdal/wiki/DownloadingGdalBinaries ).如果生成的文件仍然太大,则可以使用mapshaper压缩( http://www.mapshaper.org/ -它同时使用shapefile和GeoJSON格式!),并在必要时(如果文件大小仍然有问题)将生成的地图从GeoJSON转换为topojson(请参阅:

  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).

您是否需要在地图中使用位置数据? (例如,您可能需要在地图上标记某个城市的位置,但未在原始SVG上绘制该城市),因此更容易获得shapefile并将其转换为GeoJSON(使用ogr2​​ogr),因为您很可能会这样做在下载的SVG文件上没有地理位置信息.

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.

如果要创建一个弧形并且没有地理位置要求,则可以直接将SVG直接添加到页面中,并使用D3将数据映射到图像!将SVG放入页面后,您甚至可以手动编辑所有路径数据,以包含可简化D3作业的类和ID.

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.

这篇关于使用ogr2​​ogr将svg转换为geojson失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆