[geos-devel] Re: GEOS / SRID / WKB

strk at refractions.net strk at refractions.net
Wed Feb 1 20:57:33 EST 2006


Charlie, we're playing dirty here, even for Z values.
One thing is accepting "extensions", another thing is spitting them out.
Z,M and SRID flags are postgis-specific.
The next update on OGC dox will define a different way to express
Z and M for example, and won't say anything about SRID.

The most correct way to support multiple different specs
would be to provide a method to specify which one to use.

For example:

	WKBWriter writer;
	writer.setFormat(DIALECT);
	writer.write(geom);

Same would apply to WKBReader and to WKT reader/writer.

--strk;

On Wed, Feb 01, 2006 at 06:50:07PM -0700, Charlie Savage wrote:
> I'd like to be able to read/write SRID information from GEOS using the 
> WKB Reader/Writer.  Currently the WKBReader reads the SRID value in an 
> extended WKB format, but then tosses it away.  Attached is a patch that 
> saves the SRID value by calling setSRID on the newly created geometry. 
> 
> It would also be nice if WKBWriter could output SRID values.  Looking 
> through the code, it would be easy enough to write this information 
> out.  However, if a geometry has an SRID, the output WKB value would be 
> one byte longer plus have an SRID flag in the geomtype byte.  So this 
> would break existing code that reads wkb values if a geometry has an 
> SRID.  I'm not sure if this is an issue or not, since I see the SRID 
> field on a geometry is not documented.  Is this a frequently used 
> feature?  An alternative of course would be having a separate method, 
> maybe called writeExtended or some such thing.  
> 
> Thanks,
> 
> Charlie

> Index: source/io/WKBReader.cpp
> ===================================================================
> RCS file: /home/cvs/postgis/geos/source/io/WKBReader.cpp,v
> retrieving revision 1.15
> diff -u -r1.15 WKBReader.cpp
> --- source/io/WKBReader.cpp	20 Jan 2006 00:59:55 -0000	1.15
> +++ source/io/WKBReader.cpp	2 Feb 2006 01:44:16 -0000
> @@ -230,31 +230,43 @@
>  	cout<<"WKB hasSRID: "<<hasZ<<endl;
>  #endif
>  
> -	if (hasSRID) dis.readInt(); // skip SRID
> -
> +	int srid = -1;
> +	if (hasSRID) srid = dis.readInt(); // read SRID
>  
>  	// allocate space for ordValues 
>  	if ( ordValues.size() < inputDimension )
>  		ordValues.resize(inputDimension);
>  
> +	Geometry * result;
>  
>  	switch (geometryType) {
>  		case WKBConstants::wkbPoint :
> -			return readPoint();
> +			result = readPoint();
> +			break;
>  		case WKBConstants::wkbLineString :
> -			return readLineString();
> +			result = readLineString();
> +			break;
>  		case WKBConstants::wkbPolygon :
> -			return readPolygon();
> +			result = readPolygon();
> +			break;
>  		case WKBConstants::wkbMultiPoint :
> -			return readMultiPoint();
> +			result = readMultiPoint();
> +			break;
>  		case WKBConstants::wkbMultiLineString :
> -			return readMultiLineString();
> +			result = readMultiLineString();
> +			break;
>  		case WKBConstants::wkbMultiPolygon :
> -			return readMultiPolygon();
> +			result = readMultiPolygon();
> +			break;
>  		case WKBConstants::wkbGeometryCollection :
> -			return readGeometryCollection();
> +			result = readGeometryCollection();
> +			break;
> +		default:
> +			throw new ParseException("Unknown WKB type " + geometryType);
>  	}
> -	throw new ParseException("Unknown WKB type " + geometryType);
> +
> +	result->setSRID(srid);
> +	return result;
>  }
>  
>  Point *
> 




-- 

 +----------------------------------------+
 | Fight against software patents in EU!  |
 | www.ffii.org www.nosoftwarepatents.org |
 +----------------------------------------+




More information about the geos-devel mailing list