Discussion:
[gdal-dev] Use java swig binding to create geojson, the creation is successful but the geojson is incomplete
zs s
2021-05-14 04:06:38 UTC
Permalink
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?
Even Rouault
2021-05-14 10:52:31 UTC
Permalink
See https://gdal.org/java/org/gdal/ogr/DataSource.html#delete()
--
http://www.spatialys.com
My software is free, but my time generally not.
Loading...