[gdal-dev] Use java swig binding to create geojson, the creation is successful but the geojson is incomplete
zs s
cmulershen at gmail.com
Thu May 13 21:06:38 PDT 2021
Hi, this is my create geojson code:
public static void main(String[] args) {
String path = "test.geojson";
ogr.RegisterAll();
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
String driverName = "GeoJson";
Driver driver = ogr.GetDriverByName(driverName);
DataSource dataSource = driver.CreateDataSource(path);
Layer layer = dataSource.CreateLayer("test", null, ogr.wkbPoint);
FieldDefn strField = new FieldDefn("str", ogr.OFTString);
layer.CreateField(strField);
FieldDefn intField = new FieldDefn("integer", ogr.OFTInteger);
layer.CreateField(intField);
FeatureDefn featureDefn = layer.GetLayerDefn();
for (int i = 0; i < 2; i++) {
Feature feature = new Feature(featureDefn);
feature.SetField("str", "test test test test");
feature.SetField("integer", i);
double x = 120 + (double) i / 1000;
double y = 30 + (double) i / 1000;
Geometry geometry = Geometry.CreateFromWkt(String.format("POINT
(%f %f)", x, y));
feature.SetGeometry(geometry);
layer.CreateFeature(feature);
}
dataSource.SyncToDisk();
}
It can run successfully, but result is incomplete:
{
"type": "FeatureCollection",
"name": "test",
"features": [
{ "type": "Feature", "properties": { "str": "test test test test",
"integer": 0 }, "geometry": { "type": "Point", "coordinates": [ 120.0, 30.0
] } },
{ "type": "Feature", "properties": { "str": "test test test test",
"integer": 1 }, "geometry": { "type": "Point", "coordinates": [ 120.001,
30.001 ] } }
Can it be created in this way or my code is wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210514/2aaa9dc6/attachment.html>
More information about the gdal-dev
mailing list