0

Encode:

1- A way of encoding a FeatureType is :

SimpleFeatureType TYPE = DataUtilities.createType("Location", "geom:Point,name:String");
GML encode = new GML(Version.GML2);
encode.setBaseURL(new URL("http://localhost/"));
encode.encode(System.out, TYPE);

2- Another way of encoding:

 FeatureTypeTransformer t = new FeatureTypeTransformter();
 t.transform(TYPE,System.out);

Decode:

I have a xsd of a featuretype:

<?xml version="1.0" encoding="UTF-8"?>
<xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" name="jahanserver:test1_Type">
<xs:complexContent>
    <xs:extension base="gml:AbstractFeatureType">
        <xs:sequence>
            <xs:element name="the_geom" minOccurs="1" nillable="false" type="gml:GeometryAssociationType"/>
            <xs:element name="name" minOccurs="1" nillable="false">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:maxLength value="2147483647"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:sequence>
    </xs:extension>
</xs:complexContent>
</xs:complexType>

And I want to decode it as a SimpleFeatureType. How can I do that?

Possible solution 1:
The GML2ParsingUtils Class may be helpful. It has a method named featuretype for parsing schema, but I don't know how to prepare the method arguments.

Possible solution 2:

GML gml = new GML(GML.Version.GML2);
gml.decodeSimpleFeatureType(url,name);

But I don't have any url. I have a HttpServletRequest containing a bare featuretype with complexType xml root.

2

The easy way is to go with option 2 and the URL it wants is the location of the XSD file which will be in the top of the GML that is within your ServletRequest. So you need to open the root element and extract the namespaces and schema URLs.

Then you can create the name and URL from that:

GML gml = new GML(Version.WFS1_0);
gml.setCoordinateReferenceSystem( DefaultGeographicCRS.WGS84 );

Name typeName = new NameImpl("http://www.openplans.org/topp", "states");
SimpleFeatureType featureType = gml.decodeSimpleFeatureType(schemaLocation, typeName ); 

Alternatively you can go through the hassle of parsing the XML yourself and then use option 1 to extract the schema from the W3C Node you have:

schema = GML2ParsingUtils.featureType(node);
  • The xsd does not contain any urls. See the xsd in the question body – Dariush Jul 7 '15 at 9:38
  • the URL points to the XSD - the GML contains this – Ian Turton Jul 7 '15 at 9:49
  • iant! the request body is a bare featuretype (as I mentioned in the question).I want only decode a featuretype, not a feature! – Dariush Jul 7 '15 at 9:56
  • 1
    then look in decodeSimpleFeatureType and see what it does with the URL's inputstream and copy that – Ian Turton Jul 7 '15 at 10:16
  • It is hard!!!!!!!!! – Dariush Jul 7 '15 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.