[gdal-dev] Shapefile with one feature and many incrementally-added vertices is huge

Nik Sands nik at nixanz.com
Thu Jan 19 02:21:20 PST 2017


Hi,

My iOS app has a feature where it uses GDAL 1.11 to record to two shapefiles simultaneously.  One is a point 2.5D feature class and it writes a point feature to this feature class for every location that iOS sends.  The other is a line 2.5D feature class with a single line feature and a vertex is added to the line for every location that iOS sends.

I’ve found that the line shapefile ends up being huge, while the point shapefile is manageable.  For example, I recently tested it out tracking a walk I did over a few hours and 6,000 vertices in the one line feature resulted in a shapefile of 500 MB (this is the .shp file itself, not the .dbf, etc).  The shapefile is not sync’d to disk in between adding vertices.  Just once at the beginning and once the end.

Is this sort of file size expected?  Can I do this in a way that would use less storage space?

ogr2ogr will copy this 500MB shapefile to a 155KB shapefile.  So it is clearly wasted space.  Is there some way that I can have it write the original shapefil without wasting this space in the first place?

The code used to add vertices is below.

Thanks for any insights that you can provide.

Cheers,
Nik.


Code (Objective-C):
————————————————————
- (BOOL)addVertexAtCoordX:(double)x Y:(double)y Z:(double)z {
	OGRGeometryH geom = OGR_F_GetGeometryRef(_feature);
	
	if ( geom ) {
		geom = OGR_G_Clone(geom);
	} else {
		geom = OGR_G_CreateGeometry(OGR_FD_GetGeomType(OGR_F_GetDefnRef(_feature)));
	}
	
	OGR_G_AddPoint(geom, x, y, z);
	
	if ( OGR_F_SetGeometryDirectly(_feature, geom) != OGRERR_NONE ) {
		OGR_G_DestroyGeometry(geom);
		NSLog(@"Failed to set geometry for feature.");
		return NO;
	}
	if ( OGR_L_SetFeature(_layer.layer, _feature) != OGRERR_NONE ) { 
		NSLog(@"Failed to update feature geometry");
		return NO;
	}
	
	return YES;
}
————————————————————

========================================================
NIK SANDS
Line Tamer | Time Traveller | Space Cadet



More information about the gdal-dev mailing list