Hi Robert,

The way we associate srs information with a geometry is with
Geometry.getUserData()/setUserData(). Its not ideal but JTS does not
give us a better way to store srs information with a geometry beyond the
srid.

So here is how you can do it:

//the geometry
Geometry g = ...;

//crab a crs object
CoordinateReferenceSystem crs = CRS.decode( "EPSG:4326" );
g.setUserData( crs );

//encode...

However this brings up a reasonable point. That if no user data is set
perhaps the encode should use Goemetry.getSRID().

Let me know if that works for you.

-Justin

Robert Jacolin wrote:
> Hello,
> 
> In my quest to execute XQuery with GIS data, I found a problem with 
> WKTReader / WKTWriter.
> 
> In the first version of my application, I let the user to write a WKT 
> Polygon to create a criteria for the request (for example : return all 
> polygon which contains the POINT (278415 187644) ). I used this point to 
> create my XQuery. So I used the class WKTReader to create a Geometry 
> object, which I serialize again with org.geotools.xml.Encoder :
> 
> FeatureCollection featureCollection = 
> DefaultFeatureCollections.newCollection();
> org.geotools.xml.Configuration configuration = new 
> org.geotools.gml2.GMLConfiguration(); // For test, I'm working on GML V2
> org.geotools.xml.Encoder encoder = new org.geotools.xml.Encoder( 
> configuration );
> 
> // output stream to serialize to
> OutputStream xml = new ByteArrayOutputStream();
> 
> // encode. hmmm, guess I can do something better ?
> if("Point".equalsIgnoreCase(geo.getGeometryType()))
>     encoder.encode(geo, GML.Point, xml);
> else if("Polygon".equalsIgnoreCase(geo.getGeometryType()))
>     encoder.encode(geo, GML.Polygon, xml);
> else if("LineString".equalsIgnoreCase(geo.getGeometryType()))
>     encoder.encode(geo, GML.LineString, xml);
> else if("LinearRing".equalsIgnoreCase(geo.getGeometryType()))
>     encoder.encode(geo, GML.LinearRing, xml);
> 
> The point serialized in GML is :
> <gml:Point xmlns:gml="http://www.opengis.net/gml";   
> xmlns:xlink="http://www.w3.org/1999/xlink";>
>     <gml:coord><gml:X>278415.0</gml:X><gml:Y>187644.0</gml:Y></gml:coord>
> </gml:Point>
> 
> As you see, the srsName is not present. If I execute the request, 
> nothing is returned. If I add the attribute srsName="osgb:BNG" for 
> gml:Point, I get my objects.
> Is it a bug ? Perhaps, I misunderstood something ?
> 
> I tried to put the SRS ID in the Geometry without success :
> geo.setSRID(4326);
> 
> The SR ID is not the second part of the srsName (authority:ID) ?
> 
> How can I store the srsName in my GML ?
> 
> When I get the result, I need to parse the GML fragment. I did it but 
> the osgb:BNG authority is not found. In google, I found this issue :
> http://jira.codehaus.org/browse/GEOT-1307
> 
> How can I declare an authority ?
> I tried :
> crs = CRS
>                     .parseWKT("PROJCS[\"OSGB 1936 / British National 
> Grid\", "
>                             + "GEOGCS[\"OSGB 1936\", "
>                             + "DATUM[\"OSGB_1936\", "
>                             + "SPHEROID[\"Airy 1830\", 6377563.396, 
> 299.3249646, AUTHORITY[\"EPSG\",\"7001\"]], "
>                             + "AUTHORITY[\"EPSG\",\"6277\"]], "
>                             + "PRIMEM[\"Greenwich\", 0.0, 
> AUTHORITY[\"EPSG\",\"8901\"]], "
>                             + "UNIT[\"degree\", 0.017453292519943295], "
>                             + "AXIS[\"Longitude\", EAST], "
>                             + "AXIS[\"Latitude\", NORTH], "
>                             + "AUTHORITY[\"EPSG\",\"4277\"]], "
>                             + "PROJECTION[\"Transverse_Mercator\"], "
>                             + "PARAMETER[\"central_meridian\", -2.0], "
>                             + "PARAMETER[\"latitude_of_origin\", 49.0], "
>                             + "PARAMETER[\"scale_factor\", 0.9996012717], "
>                             + "PARAMETER[\"false_easting\", 400000.0], "
>                             + "PARAMETER[\"false_northing\", -100000.0], "
>                             + "UNIT[\"m\", 1.0], " + "AXIS[\"x\", EAST], "
>                             + "AXIS[\"y\", NORTH], "
>                             + "AUTHORITY[\"osgb\",\"BNG\"]]");
>             String code = CRS.lookupIdentifier(crs, true );
> But I get
> org.opengis.referencing.FactoryException: Les extensions de Geotools 
> sont requises pour l'opération "getIdentifiedObjectFinder".
> which means The Geotools extensions are required for the operation 
> "getIdentifiedObjectFinder".
> 
> Thanks in advance for your help.
> 
> Regards,
> 


-- 
Justin Deoliveira
The Open Planning Project
http://topp.openplans.org

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to