Java Code Examples for org.citygml4j.xml.io.CityGMLInputFactory#setProperty()

The following examples show how to use org.citygml4j.xml.io.CityGMLInputFactory#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilteredReader.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();

	System.out.println(df.format(new Date()) + "reading only roads from CityGML file LOD2_CityObjectGroup_v100.gml");
	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE);

	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_CityObjectGroup_v100.gml"));
	reader = in.createFilteredCityGMLReader(reader, new CityGMLInputFilter() {

		// return true if you want to consume the CityGML feature
		// of the given qualified XML name, false otherwise
		public boolean accept(QName name) {
			return Modules.isModuleNamespace(name.getNamespaceURI(), CityGMLModuleType.TRANSPORTATION)
					&& name.getLocalPart().equals("Road");
		}
		
	});

	System.out.println(df.format(new Date()) + "printing road features");
	while (reader.hasNext()) {
		Road road = (Road)reader.nextFeature();
		System.out.println(df.format(new Date()) + "found Road with gml:id " + road.getId());	
		
		System.out.println(df.format(new Date()) + "\t" + road.getTrafficArea().size() + " traffic area(s)");	
		System.out.println(df.format(new Date()) + "\t" + road.getAuxiliaryTrafficArea().size() + " auxiliary traffic area(s)");	
	}

	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example 2
Source File: FeatureChunkReader.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();
	
	System.out.println(df.format(new Date()) + "reading CityGML file LOD3_Building_v200.gml feature by feature");
	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE);
	in.setProperty(CityGMLInputFactory.EXCLUDE_FROM_SPLITTING, new QName[]{new QName("Door"), new QName("Address")});

	// see difference when setting to true
	in.setProperty(CityGMLInputFactory.KEEP_INLINE_APPEARANCE, false);
	
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD3_Building_v200.gml"));
	
	System.out.println(df.format(new Date()) + "printing feature currently read and its (transitive) parents");
	while (reader.hasNext()) {
		CityGML chunk = reader.nextFeature();	
		System.out.println("found: " + chunk.getCityGMLClass());
		
		if (reader.isSetParentInfo()) {
			ParentInfo parentInfo = reader.getParentInfo();
			System.out.println(" --parent: " + parentInfo.getCityGMLClass());
			
			while ((parentInfo = parentInfo.getParentInfo()) != null)
				System.out.println(" --transitive parent: " + parentInfo.getCityGMLClass());
		}
		
	}

	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example 3
Source File: ValidatingSimpleReader.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();
	
	System.out.println(df.format(new Date()) + "reading ADE-enriched CityGML file LOD2_SubsurfaceStructureADE_invalid_v100.gml");
	System.out.println(df.format(new Date()) + "ADE schema file is read from xsi:schemaLocation attribute on root XML element");
	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.NO_SPLIT);
	in.parseSchema(new File("datasets/schemas/CityGML-SubsurfaceADE-0_9_0.xsd"));

	in.setProperty(CityGMLInputFactory.USE_VALIDATION, true);	
	in.setValidationEventHandler(event -> {
           System.out.print("[" + event.getLocator().getLineNumber() + "," + event.getLocator().getColumnNumber() + "] ");
           System.out.println(event.getMessage());
           return true;
       });
	
	System.out.println(df.format(new Date()) + "validating ADE-enriched CityGML document whilst reading");
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_SubsurfaceStructureADE_invalid_v100.gml"));
	reader.nextFeature();

	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example 4
Source File: ValidatingChunkReader.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();
	
	System.out.println(df.format(new Date()) + "reading ADE-enriched CityGML file LOD2_SubsurfaceStructureADE_invalid_v100.gml feature by feature");
	System.out.println(df.format(new Date()) + "ADE schema file is read from xsi:schemaLocation attribute on root XML element");
	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE);
	in.setProperty(CityGMLInputFactory.USE_VALIDATION, true);
	in.registerSchemaLocation("http://www.citygml.org/ade/sub/0.9.0", new File("datasets/schemas/CityGML-SubsurfaceADE-0_9_0.xsd"));
		
	ValidationEventHandlerImpl validationEventHandler = new ValidationEventHandlerImpl();
	in.setValidationEventHandler(validationEventHandler);
	
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_SubsurfaceStructureADE_invalid_v100.gml"));
	
	System.out.println(df.format(new Date()) + "validating features whilst reading from file");
	while (reader.hasNext()) {
		CityGML chunk = reader.nextFeature();			

		String type;
		if (chunk instanceof ADEGenericElement){
			Element element = ((ADEGenericElement)chunk).getContent();
			type = element.getPrefix() + ':' + element.getLocalName();
		} else
			type = chunk.getCityGMLClass().toString();
		
		System.out.print(type + ": ");
		System.out.println(validationEventHandler.isValid ? "valid" : "invalid (see error messages above)");

		validationEventHandler.isValid = true;
	}

	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example 5
Source File: MissingSchemaReference.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();

	System.out.println(df.format(new Date()) + "setting up schema handler");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	schemaHandler.setSchemaEntityResolver(new SchemaEntityResolver());
	schemaHandler.setErrorHandler(new SchemaParseErrorHandler());

	System.out.println(df.format(new Date()) + "reading ADE-enriched CityGML file LOD0_Railway_NoiseADE_missing_ADE_reference_v200.gml");
	System.out.println(df.format(new Date()) + "note: the input document is lacking a reference to the ADE schema document");
	CityGMLInputFactory in = builder.createCityGMLInputFactory(schemaHandler);
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE);
	
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD0_Railway_NoiseADE_missing_ADE_reference_v200.gml"));
	
	while (reader.hasNext()) {
		CityGML citygml = reader.nextFeature();
		
		if (citygml instanceof AbstractFeature)
			System.out.println("Found CityGML: " + citygml.getCityGMLClass());
		else if (citygml instanceof ADEGenericElement)
			System.out.println("Found ADE: " + ((ADEGenericElement)citygml).getContent().getLocalName());
	}
	
	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example 6
Source File: WrongSchemaLocation.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();

	System.out.println(df.format(new Date()) + "setting up schema handler");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	schemaHandler.setSchemaEntityResolver(new SchemaEntityResolver());
	schemaHandler.setErrorHandler(new SchemaParseErrorHandler());
	
	// register false schema location in order to provoke a schema parse error
	schemaHandler.registerSchemaLocation("http://www.citygml.org/ade/noise_de/2.0", 
			new File("/nowhere/nofile.xsd"));

	System.out.println(df.format(new Date()) + "reading ADE-enriched CityGML file LOD0_Railway_NoiseADE_v200.gml");
	CityGMLInputFactory in = builder.createCityGMLInputFactory(schemaHandler);
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE);

	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD0_Railway_NoiseADE_v200.gml"));
	
	while (reader.hasNext()) {
		CityGML citygml = reader.nextFeature();
		
		if (citygml instanceof AbstractFeature)
			System.out.println("Found CityGML: " + citygml.getCityGMLClass());
		else if (citygml instanceof ADEGenericElement)
			System.out.println("Found ADE: " + ((ADEGenericElement)citygml).getContent().getLocalName());
	}
	
	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example 7
Source File: AdditionalObjectsHandler.java    From web-feature-service with Apache License 2.0 4 votes vote down vote up
protected void writeObjects() {
    if (!shouldRun)
        return;

    try {
        // close writers to flush buffers
        for (CityModelWriter tempWriter : tempWriters.values())
            tempWriter.close();

        CityGMLInputFactory in = cityGMLBuilder.createCityGMLInputFactory();
        in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_COLLECTION_MEMBER);

        startAdditionalObjects();

        Attributes dummyAttributes = new AttributesImpl();
        String propertyName = "member";
        String propertyQName = saxWriter.getPrefix(Constants.WFS_NAMESPACE_URI) + ":" + propertyName;

        // iterate over temp files and send additional objects to response stream
        for (Path tempFile : tempFiles.values()) {
            try (CityGMLReader tempReader = in.createCityGMLReader(tempFile.toFile())) {
                while (tempReader.hasNext()) {
                    XMLChunk chunk = tempReader.nextChunk();
                    if ("CityModel".equals(chunk.getTypeName().getLocalPart())
                            && Modules.isCityGMLModuleNamespace(chunk.getTypeName().getNamespaceURI()))
                        continue;

                    ContentHandler handler;
                    if (transformerChainFactory == null)
                        handler = saxWriter;
                    else {
                        TransformerChain chain = transformerChainFactory.buildChain();
                        chain.tail().setResult(new SAXResult(saxWriter));
                        handler = chain.head();
                        handler.startDocument();
                    }

                    handler.startElement(Constants.WFS_NAMESPACE_URI, propertyName, propertyQName, dummyAttributes);
                    chunk.send(handler, true);
                    handler.endElement(Constants.WFS_NAMESPACE_URI, propertyName, propertyQName);

                    if (transformerChainFactory != null)
                        handler.endDocument();
                }
            }
        }

    } catch (CityGMLWriteException | CityGMLBuilderException | CityGMLReadException | SAXException | TransformerConfigurationException e) {
        eventDispatcher.triggerSyncEvent(new InterruptEvent("Failed to write additional objects.", LogLevel.ERROR, e, eventChannel, this));
    }
}
 
Example 8
Source File: MultithreadedReader.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();
	
	// create a fixed thread pool
	int nThreads = Runtime.getRuntime().availableProcessors() * 2;
	System.out.println(df.format(new Date()) + "setting up thread pool with " + nThreads + " threads");
	ExecutorService service = Executors.newFixedThreadPool(nThreads);
	
	System.out.println(df.format(new Date()) + "reading LOD3_Railway_v200.gml in a multithreaded fashion");
	
	// create a validating reader that chunks the input file on a per feature level
	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE);
	in.setProperty(CityGMLInputFactory.USE_VALIDATION, true);
	
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD3_Railway_v200.gml"));
	
	while (reader.hasNext()) {
		// whereas the nextFeature() method of a CityGML reader completely unmarshals the 
		// XML chunk to an instance of the citygml4j object model and optionally validates
		// it before returning, the nextChunk() method returns faster but only provides a
		// set of SAX events.		
		final XMLChunk chunk = reader.nextChunk();
		
		// we forward every XML chunk to a separate thread of the thread pool
		// for unmarshalling and validation
		service.execute(() -> {
               try {
                   chunk.unmarshal();
               } catch (UnmarshalException | MissingADESchemaException e) {
                   //
               }

               // invoking the hasPassedXMLValidation() method prior to unmarshal()
               // or when using a non-validating CityGML reader will always yield false.
               boolean isValid = chunk.hasPassedXMLValidation();

               System.out.println("Thread '" + Thread.currentThread().getName() + "' unmarshalled " + chunk.getCityGMLClass() + "; valid: " + isValid);
           });
	}
	
	System.out.println(df.format(new Date()) + "shutting down threadpool");
	service.shutdown();
	service.awaitTermination(120, TimeUnit.SECONDS);
	
	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example 9
Source File: ObjectTreeValidationUsingSplitter.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	/*
	 * PLEASE NOTE, that you receive less errors if the in-memory objects
	 * derived from the input document are validated than if the input document
	 * itself is validated.
	 * reason: citygml4j tries to reconstruct a valid object tree from the
	 * input document. Generally, this means
	 * 1) Invalid order of XML elements will be corrected automatically (see ADDRESS element)
	 * 2) Invalid text values of XML elements cannot be automatically corrected
	 *    and thus will be reported (see, e.g., gml:id of BUILDING element)
	 * 3) Invalid XML child elements will be omitted in the object tree (see CLOSURESURFACE element)
	 * 
	 * Due to 3) you should always make sure to generate object trees from 
	 * valid CityGML documents!
	 */
	
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();
	
	System.out.println(df.format(new Date()) + "parsing ADE schema file CityGML-SubsurfaceADE-0_9_0.xsd");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	schemaHandler.parseSchema(new File("datasets/schemas/CityGML-SubsurfaceADE-0_9_0.xsd"));

	System.out.println(df.format(new Date()) + "reading ADE-enriched CityGML file LOD2_SubsurfaceStructureADE_invalid_v100.gml");
	CityGMLInputFactory in = builder.createCityGMLInputFactory(schemaHandler);
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.NO_SPLIT);

	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_SubsurfaceStructureADE_invalid_v100.gml"));
	CityGML citygml = reader.nextFeature();		
	reader.close();
	
	System.out.println(df.format(new Date()) + "creating citygml4j Validator");
	Validator validator = builder.createValidator(schemaHandler);		
	validator.setValidationEventHandler(event -> {
           System.out.println("\t" + event.getMessage());
           return true;
       });
	
	System.out.println(df.format(new Date()) + "creating citygml4j FeatureSplitter and splitting document into single features");
	FeatureSplitter splitter = new FeatureSplitter()
			.setSchemaHandler(schemaHandler)
			.setSplitMode(FeatureSplitMode.SPLIT_PER_FEATURE)
			.splitCopy(true);
	
	System.out.println(df.format(new Date()) + "iterating over splitting result and validating features against CityGML 1.0.0");
	for (CityGML feature : splitter.split(citygml)) {
		
		String type;
		if (feature instanceof ADEGenericElement){
			Element element = ((ADEGenericElement)feature).getContent();
			type = element.getPrefix() + ':' + element.getLocalName();
		} else
			type = feature.getCityGMLClass().toString();
		
		System.out.println("Validating " + type);
		validator.validate(feature, CityGMLVersion.v1_0_0);
	}
	
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}