3

我有一个要转换为 GeoJson 的 csv 文件。

lon,lat,val,id
-97.1589432,25.9642008,0,2690
-97.1682294,25.9761856,0,2691
-97.1775156,25.9881704,0,2692

我运行以下 ogr2ogr 命令

ogr2ogr -f GEOJson geo_result.json source.csv

我得到了这个结果

{
"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 }
]
}

为什么几何为空?我如何告诉 ogr2ogr 哪些值是纬度和经度?

4

1 回答 1

8

您需要将文件包装在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>

然后使用该VRT文件作为输入:

ogr2ogr -f GEOJson geo_result.json source.vrt

QGIS(使用 OGR)有一个界面可以巧妙地猜测列,而且效果很好。因此,如果您必须仅使用一次转换,则可能值得尝试使用 QGIS 之类的 GUI。

有关更多详细信息,请参阅CSVOGR 的驱动程序页面: http ://www.gdal.org/ogr/drv_csv.html

于 2014-02-20T07:43:32.647 回答