zs s
2021-05-14 04:06:38 UTC
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?
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?