From: Justin D. <jde...@op...> - 2011-05-24 14:30:57
|
Hi Ken, On Fri, May 20, 2011 at 7:21 AM, Ken Magnes <Ken...@ra...> wrote: > I'm using GeoTools v2.7.0.1 and having issues with GML encoding. I have > tried both the gml2.GMLConfiguration with the org.geotools.xml.Encoder class > and also the org.geotools.GML utility class. > > > > 1. Could you please point out what may be wrong with the following GML2 > encoding example. Also, does the structure of the SimpleFeatureCollection > (how the simple feature types are created) impact the ability to encode with > a particular schema? > If you have your own application schema the class you probably want to use is ApplicationSchemaConfiguration: ApplicationSchemaConfiguration cfg = new ApplicationSchemaConfiguration(" http://ogr.maptools.org", " file:///C:/Projects/GeoTools/schema/results.xsd"); Encoder e = new Encoder(); ... e.encode(featureCollection, fcName, os); Creating a custom xsd like that generally won't work so I would expect an empty instance document. > > public void encode(SimpleFeatureCollection fc, OutputStream os) throws > IOException > > { > > org.geotools.xml.XSD xsd = new org.geotools.xml.XSD() { > > public String getNamespaceURI() { > > return "http://ogr.maptools.org/"; > > } > > public String getSchemaLocation() > > { > > return "file:///C:/Projects/GeoTools/schema/results.xsd"; > > } > > protected void addDependencies(Set dependencies) { > > dependencies.add(org.geotools.gml2.GML.getInstance()); > > } > > }; > > org.eclipse.xsd.XSDSchema schema = xsd.getSchema(); > > QName fcName = new QName("http://ogr.maptools.org/", > "FeatureCollection"); > > > > org.geotools.gml2.GMLConfiguration config = new > org.geotools.gml2.GMLConfiguration(); > > org.geotools.xml.Encoder encoder = new > org.geotools.xml.Encoder(config, schema); > > //encoder.setSchemaLocation("http://ogr.maptools.org/", > "file:///C:/Projects/GeoTools/schema/results.xsd"); > > encoder.setIndentSize(2); > > > > encoder.encode(featureCollection, fcName, os); > > System.out.println("Encoded " + featureCollection.size() + " > features"); > > } > > > > There are a total of 11 features in the feature collection with mixed > geometry types (MultiPoint, Polygon, LineString, GeometryCollection, etc.). > The encoded output is below and the results.xsd file is attached. There are > no warning or error messages. > > > > <?xml version="1.0" encoding="UTF-8"?> > > <ogr:FeatureCollection xmlns:ogr="http://ogr.maptools.org/" xmlns:gml=" > http://www.opengis.net/gml"/> > > > > > > Below is some output from the feature.getType() method. > > ======================================================= > > > > SimpleFeatureTypeImpl http://ogr.maptools.org/:MultiPoint identified > extends > Feature(groupedFeatureAttributes:groupedFeatureAttributes,graphicWidth:graphicWidth,fillColor:fillColor,olTool:olTool,name:name, > > display:disp > lay,graphicHeight:graphicHeight,bufferM:bufferM,type:type,strokeColor:strokeColor,fillOpacity:fillOpacity,geometry:geometry) > > > > SimpleFeatureTypeImpl http://ogr.maptools.org/:Polygon identified extends > Feature(groupedFeatureAttributes:groupedFeatureAttributes,graphicWidth:graphicWidth,fillColor:fillColor,olTool:olTool,name:name, > > display:disp > lay,graphicHeight:graphicHeight,bufferM:bufferM,type:type,strokeColor:strokeColor,fillOpacity:fillOpacity,geometry:geometry) > > > > SimpleFeatureTypeImpl http://ogr.maptools.org/:MultiLineString identified > extends > Feature(groupedFeatureAttributes:groupedFeatureAttributes,graphicWidth:graphicWidth,fillColor:fillColor,olTool:olTool,name:name, > > display:disp > lay,graphicHeight:graphicHeight,bufferM:bufferM,type:type,strokeColor:strokeColor,fillOpacity:fillOpacity,geometry:geometry) > > > > SimpleFeatureTypeImpl http://ogr.maptools.org/:GeometryCollectionidentified extends > Feature(groupedFeatureAttributes:groupedFeatureAttributes,graphicWidth:graphicWidth,fillColor:fillColor,olTool:olTool,name:name, > > display:disp > lay,graphicHeight:graphicHeight,bufferM:bufferM,type:type,strokeColor:strokeColor,fillOpacity:fillOpacity,geometry:geometry) > > > > > > Below is output from one of the features. > > ========================================= > > SimpleFeatureImpl:MultiPoint=[SimpleFeatureImpl.Attribute: > groupedFeatureAttributes<groupedFeatureAttributes > id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=, SimpleFeatureImpl.Attribute: > graphicWidth<graphicWidth id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=null, > SimpleFeatureImpl.Attribute: fillColor<fillColor > id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=#ee9900, > SimpleFeatureImpl.Attribute: olTool<olTool > id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=1, SimpleFeatureImpl.Attribute: > name<name id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=Point1, > SimpleFeatureImpl.Attribute: display<display > id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=, SimpleFeatureImpl.Attribute: > graphicHeight<graphicHeight id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=null, > SimpleFeatureImpl.Attribute: bufferM<bufferM > id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=0.0, SimpleFeatureImpl.Attribute: > type<type id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=Point, > SimpleFeatureImpl.Attribute: strokeColor<strokeColor > id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=#000000, > SimpleFeatureImpl.Attribute: fillOpacity<fillOpacity > id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=1, SimpleFeatureImpl.Attribute: > geometry<geometry id=5b6124a5-0c42-47a6-ae9f-26189d81fbad>=MULTIPOINT > ((85.140225 61.273128))] > > > > > > 2. Since I am trying to represent a feature collection using GML that can > contain mixed types and the features will have some custom > attributes/properties (like GeoJSON), is there an exising defacto "standard" > feature collection GML-based schema that can be leveraged (like some WFS > feature collection schema)? > > > Not really, you have the plain wfs feature collection and that is about it. Its up to your application schema to be flexible enough to represent the content. And if its too irregular to represent as a GML application schema then it would seem GML is not really appropriate as an output format. That said the encoder should be able to handle features like this and encode them on the fly. > > > 3. I do not see any encoding examples in > http://svn.osgeo.org/geotools/trunk/modules/extension/xsd/xsd-gml2/src/test/java/org/geotools/gml2/GMLApplicationSchemaParsingTest.javanor in any of the other test files inside that package. > > > There is not much in the way of encoding utilities application schemas in geotools. There are some examples in geoserver code: http://svn.codehaus.org/geoserver/trunk/src/wfs/src/main/java/org/geoserver/wfs/xml/v1_1_0/XmlSchemaEncoder.java Basically if you have an XSDSchema object for your app schema you can serialize it out with XSDResourceImpl.serialize(). > Thanks, > > Ken > > > ------------------------------------------------------------------------------ > What Every C/C++ and Fortran developer Should Know! > Read this article and learn how Intel has extended the reach of its > next-generation tools to help Windows* and Linux* C/C++ and Fortran > developers boost performance applications - including clusters. > http://p.sf.net/sfu/intel-dev2devmay > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > -- Justin Deoliveira OpenGeo - http://opengeo.org Enterprise support for open source geospatial. |