On Sun, Jan 31, 2016 at 2:37 AM Andrea Aime <andrea.a...@geo-solutions.it>
wrote:
> On Fri, Jan 29, 2016 at 4:00 PM, Justin Deoliveira <jdeol...@gmail.com>
> wrote:
>
>> These could be added as new methods to the GML facade class:
>>> SimpleFeatureType GML.decodeSchema(InputStream in)
>>> SimpleFeatureCollection GML.decodeFeatureCollection(InputStream in)
>>>
>>> I wonder if you could handle both the scan only single feature vs scan
>> full feature collection with a single additional integer argument. The
>> argument would be the number of features to “pre-scan” to compile the
>> schema. This would allow for a bit more control for larger GML collections
>> where you might not want to scan the whole collection but you want to scan
>> more than just the first. Just a thought.
>>
>
> I'm a bit perplexed... like, it seems to me the two significant values
> would be "1", aka "no null values, my collection is fully uniform" and "0",
> aka "no clue, scan till the end", when you don't know
> where the "odd one out" would be.
> I do realize that most of the time scanning the first few features would
> give you the final schema, but there is no reliability regarding the
> number of features where this happens, the odd case out being exactly the
> one where the attribute shows only in the last
> features of the series (which happens if you do a "order by myAtt desc" in
> a sql query, the null values are packed at
> the beginning of the series).
>
> My thought was that for larger GML collections you may want to lookahead
more than one feature, but you may not want to pay the cost of scanning all
features. So the values would be:
< 1 - scan everything
= 1 - scan just the first
> 1 - scan the first n features
If you don’t think that makes sense that is fine, was just an idea.
So, let me show you what I did in my little experiment, this will also
> explain why I was talking about pull
> parsing :-)
>
> My starting point is a desire to parse a feature collection in GML, and
> get back a SimpleFeatureCollection
> (streaming is not a requirement here). So I started using a normal Parser,
> which gives me back the SimpleFeatureCollection.
>
> However, noticed that the FeatureTypeCache was caching the type of the
> first feature... I then injected in the
> pico context a subclass that would not cache, and then
> DefaultFeatureCollection would start complaining in
> the logs that the features being inserted into it are not a match for its
> feature type (determined from
> the first feature).
>
> So ok, I decided to give the pull parser a try, that does not use a
> collection... here is the result:
>
> -----------------------------------
>
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileNotFoundException;
> import java.io.IOException;
>
> import javax.xml.stream.XMLStreamException;
>
> import org.geotools.gml2.FeatureTypeCache;
> import org.geotools.gml3.GMLConfiguration;
> import org.geotools.xml.PullParser;
> import org.opengis.feature.simple.SimpleFeature;
> import org.opengis.feature.type.FeatureType;
> import org.xml.sax.SAXException;
>
> public class GMLPullParserReader {
>
> /**
> * Does not cache the feature type, allowing each feature to have its
> own
> */
> private static final class FeatureTypeCacheNone extends
> FeatureTypeCache {
> @Override
> public void put(FeatureType type) {
> // no op
> }
> }
>
> public static void main(String[] args) throws XMLStreamException,
> IOException, SAXException {
> pullParse(new File("/tmp/GetFeatureResponse1.xml"));
> pullParse(new File("/tmp/GetFeatureResponse2.xml"));
> }
>
> private static void pullParse(File input)
> throws FileNotFoundException, XMLStreamException, IOException,
> SAXException {
> GMLConfiguration configuration = new GMLConfiguration();
> PullParser parser = new PullParser(configuration, new
> FileInputStream(input), SimpleFeature.class);
> parser.setContextCustomizer(context -> {
> Object instance =
> context.getComponentInstanceOfType(FeatureTypeCache.class);
> context.unregisterComponentByInstance(instance);
> context.registerComponentInstance(new FeatureTypeCacheNone());
> });
> SimpleFeature f = null;
> while((f = (SimpleFeature)parser.parse()) != null) {
> System.out.println(f.getFeatureType());
> }
> }
> }
>
> ---------------------------
>
> The two collections have features in different orders, resulting in
> different feature types in a normal
> parse... but with this trick, no problem, each feature has its own full
> feature type instead.
>
> Now, extending this code one could at the same time accumulate the
> features in a list,
> determine an all encompassing feature type, and then return a
> SimpleFeatureCollection.
> And I wanted to do all this in a method in the GML facade, to hide the
> details.
>
> Thinking about it, it's not that I really need to use a pull parser, I
> could use the normal one too,
> provided that the feature collection binding stops using a
> DefaultFeatureCollection, and
> uses a new "GMLFeatureCollection" that does not complain about mixed
> feature types :-p
>
> Hope this clarifies things a bit
>
> Cool, makes sense.
> Cheers
> Andrea
>
> --
> ==
> GeoServer Professional Services from the experts! Visit
> http://goo.gl/it488V for more information.
> ==
>
> Ing. Andrea Aime
> @geowolf
> Technical Lead
>
> GeoSolutions S.A.S.
> Via Poggio alle Viti 1187
> 55054 Massarosa (LU)
> Italy
> phone: +39 0584 962313
> fax: +39 0584 1660272
> mob: +39 339 8844549
>
> http://www.geo-solutions.it
> http://twitter.com/geosolutions_it
>
> *AVVERTENZE AI SENSI DEL D.Lgs. 196/2003*
>
> Le informazioni contenute in questo messaggio di posta elettronica e/o
> nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
> loro utilizzo è consentito esclusivamente al destinatario del messaggio,
> per le finalità indicate nel messaggio stesso. Qualora riceviate questo
> messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
> darcene notizia via e-mail e di procedere alla distruzione del messaggio
> stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
> divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
> utilizzarlo per finalità diverse, costituisce comportamento contrario ai
> principi dettati dal D.Lgs. 196/2003.
>
>
>
> The information in this message and/or attachments, is intended solely for
> the attention and use of the named addressee(s) and may be confidential or
> proprietary in nature or covered by the provisions of privacy act
> (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
> Code).Any use not in accord with its purpose, any disclosure, reproduction,
> copying, distribution, or either dissemination, either whole or partial, is
> strictly forbidden except previous formal approval of the named
> addressee(s). If you are not the intended recipient, please contact
> immediately the sender by telephone, fax or e-mail and delete the
> information in this message that has been received in error. The sender
> does not give any warranty or accept liability as the content, accuracy or
> completeness of sent messages and accepts no responsibility for changes
> made after they were sent or for other risks which arise as a result of
> e-mail transmission, viruses, etc.
>
> -------------------------------------------------------
>
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel