Gra*_*ntE 2 csv geojson ogr leaflet
我有一个csv文件,我想转换为GeoJson.
lon,lat,val,id
-97.1589432,25.9642008,0,2690
-97.1682294,25.9761856,0,2691
-97.1775156,25.9881704,0,2692
Run Code Online (Sandbox Code Playgroud)
我运行以下ogr2ogr命令
ogr2ogr -f GEOJson geo_result.json source.csv
Run Code Online (Sandbox Code Playgroud)
我得到了这个结果
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "lon": "-97.1589432", "lat": "25.9642008", "val": "0", "id": "2690" }, "geometry": null },
{ "type": "Feature", "properties": { "lon": "-97.1682294", "lat": "25.9761856", "val": "0", "id": "2691" }, "geometry": null },
{ "type": "Feature", "properties": { "lon": "-97.1775156", "lat": "25.9881704", "val": "0", "id": "2692" }, "geometry": null }
]
}
Run Code Online (Sandbox Code Playgroud)
为什么几何为零?我怎么能告诉ogr2ogr哪些值是lat&lon?
您需要将CSV文件包装在VRT指定列含义的文件中.
<OGRVRTDataSource>
<OGRVRTLayer name="source">
<SrcDataSource>source.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>WGS84</LayerSRS>
<GeometryField encoding="PointFromColumns" x="lon" y="lat"/>
</OGRVRTLayer>
</OGRVRTDataSource>
Run Code Online (Sandbox Code Playgroud)
然后使用该VRT文件作为输入:
ogr2ogr -f GEOJson geo_result.json source.vrt
Run Code Online (Sandbox Code Playgroud)
QGIS(使用OGR)有一个巧妙地猜测列的界面,并且非常有效.因此,如果您只需使用转换一次,则可能需要使用QGIS等GUI进行转换.
有关CSV详细信息,请参阅OGR 的驱动程序页面:http:
//www.gdal.org/ogr/drv_csv.html
| 归档时间: |
|
| 查看次数: |
2403 次 |
| 最近记录: |