org.citygml4j.CityGMLContext Java Examples

The following examples show how to use org.citygml4j.CityGMLContext. 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: CityJSONReaderFactory.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeContext(CityGMLFilter filter, Config config) throws FeatureReadException {
    CityJSONBuilder builder = CityGMLContext.getInstance().createCityJSONBuilder();
    try {
        factory = builder.createCityJSONInputFactory();
    } catch (CityJSONBuilderException e) {
        throw new FeatureReadException("Failed to initialize CityJSON input factory.", e);
    }

    // prepare feature filter
    typeFilter = name -> {
        Module module = Modules.getModule(name.getNamespaceURI());
        if (module != null && module.getType() == CityGMLModuleType.APPEARANCE && name.getLocalPart().equals("Appearance"))
            return config.getProject().getImporter().getAppearances().isSetImportAppearance();
        else
            return filter.getFeatureTypeFilter().isSatisfiedBy(name, true);
    };

    counterFilter = filter.getCounterFilter();
}
 
Example #2
Source File: ModuleContext.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
private void addADEModules() {
	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		for (ADEContext adeContext : context.getADEContexts()) {
			for (ADEModule module : adeContext.getADEModules()) {
				if (module.getCityGMLVersion() != version)
					continue;

				for (Module dependency : module.getDependencies()) {
					if (contains(dependency)) {
						if (adeModules == null)
							adeModules = new HashSet<>();

						adeModules.add(module);
						break;
					}
				}
			}
		}
	}
}
 
Example #3
Source File: ADEMarshaller.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public void reset(JAXBMarshaller jaxb) {
	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		this.marshallers = new HashMap<>();
		ADEMarshallerHelper helper = new ADEMarshallerHelper(jaxb);

		for (ADEContext adeContext : context.getADEContexts()) {
			boolean supportsTargetVersion = false;
			for (ADEModule module : adeContext.getADEModules()) {
				if (module.getCityGMLVersion() == jaxb.getModuleContext().getCityGMLVersion()) {
					supportsTargetVersion = true;
					break;
				}
			}

			if (supportsTargetVersion) {
				org.citygml4j.model.citygml.ade.binding.ADEMarshaller marshaller = adeContext.createADEMarshaller();
				if (marshaller != null) {
					marshaller.setADEMarshallerHelper(helper);
					for (String packageName : adeContext.getModelPackageNames())
						this.marshallers.put(packageName, marshaller);
				}
			}
		}
	}
}
 
Example #4
Source File: ADEUnmarshaller.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public ADEUnmarshaller(JAXBUnmarshaller jaxb) {
	this.jaxb = jaxb;

	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		this.unmarshallers = new HashMap<>();
		ADEUnmarshallerHelper helper = new ADEUnmarshallerHelper(jaxb);

		for (ADEContext adeContext : context.getADEContexts()) {
			org.citygml4j.model.citygml.ade.binding.ADEUnmarshaller unmarshaller = adeContext.createADEUnmarshaller();
			if (unmarshaller != null) {
				unmarshaller.setADEUnmarshallerHelper(helper);
				for (ADEModule module : adeContext.getADEModules())
					this.unmarshallers.put(module.getNamespaceURI(), unmarshaller);
			}
		}
	}
}
 
Example #5
Source File: ADEMarshaller.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public ADEMarshaller(CityJSONMarshaller json) {
    this.json = json;

    CityGMLContext context = CityGMLContext.getInstance();
    if (context.hasCityJSONExtensionContexts()) {
        marshallers = new HashMap<>();
        ADEMarshallerHelper helper = new ADEMarshallerHelper(json);

        for (ADEContext adeContext : context.getADEContexts()) {
            if (adeContext instanceof CityJSONExtensionContext) {
                CityJSONExtensionMarshaller marshaller = ((CityJSONExtensionContext) adeContext).getCityJSONExtension().createExtensionMarshaller();
                if (marshaller != null) {
                    marshaller.setADEMarshallerHelper(helper);
                    for (String packageName : adeContext.getModelPackageNames())
                        marshallers.put(packageName, marshaller);
                }
            }
        }
    }
}
 
Example #6
Source File: AdditionalObjectsHandler.java    From web-feature-service with Apache License 2.0 6 votes vote down vote up
private CityModelWriter getOrCreateCacheWriter() throws CityGMLWriteException, IOException {
    String key = Thread.currentThread().getName();
    CityModelWriter tempWriter = tempWriters.get(key);
    if (tempWriter == null) {
        // create unique temp file
        long n = new SecureRandom().nextLong();
        n = n == Long.MIN_VALUE ? 0 : Math.abs(n);
        Path tempFile = Paths.get(System.getProperty("java.io.tmpdir"), "3dcitydb-wfs", Long.toString(n) + ".tmp");
        Files.createDirectories(tempFile.getParent());

        // create temp writer
        CityGMLOutputFactory out = cityGMLBuilder.createCityGMLOutputFactory(version);
        tempWriter = out.createCityModelWriter(tempFile.toFile(), "UTF-8");
        tempWriter.setPrefixes(version);
        tempWriter.setPrefixes(CityGMLContext.getInstance().getADEContexts());
        tempWriter.setIndentString("");

        tempFiles.put(key, tempFile);
        tempWriters.put(key, tempWriter);
    }

    return tempWriter;
}
 
Example #7
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 #8
Source File: ReadingRemoteADE.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 LOD0_Railway_NoiseADE_from_Web_v200.gml");
	System.out.println(df.format(new Date()) + "remote ADE schema file is read from xsi:schemaLocation attribute on root XML element");
	CityGMLInputFactory in = builder.createCityGMLInputFactory();

	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD0_Railway_NoiseADE_from_Web_v200.gml"));
	CityGML citygml = reader.nextFeature();
	reader.close();

	System.out.println(df.format(new Date()) + "exploring ADE content of Railway element");
	CityModel cityModel = (CityModel)citygml;
	Railway railway = (Railway)cityModel.getCityObjectMember().get(0).getCityObject();
	
	if (railway.isSetGenericApplicationPropertyOfRailway()) {
		System.out.println("Found ADE content for Railway instance:\n");

		List<ADEComponent> ades = railway.getGenericApplicationPropertyOfRailway();
		for (ADEComponent ade : ades) {
			if (ade.getADEClass() == ADEClass.GENERIC_ELEMENT)
				checkADE(in.getSchemaHandler(), ((ADEGenericElement)ade).getContent(), null, 0);
		}
	}
	
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #9
Source File: ReadingLocalADE.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 LOD0_Railway_NoiseADE_v200.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();

	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD0_Railway_NoiseADE_v200.gml"));
	CityGML citygml = reader.nextFeature();
	reader.close();

	System.out.println(df.format(new Date()) + "exploring ADE content of Railway element");
	CityModel cityModel = (CityModel)citygml;
	Railway railway = (Railway)cityModel.getCityObjectMember().get(0).getCityObject();
	
	if (railway.isSetGenericApplicationPropertyOfRailway()) {
		System.out.println("Found ADE content for Railway instance:\n");

		List<ADEComponent> ades = railway.getGenericApplicationPropertyOfRailway();
		for (ADEComponent ade : ades) {
			if (ade.getADEClass() == ADEClass.GENERIC_ELEMENT)
				checkADE(in.getSchemaHandler(), ((ADEGenericElement)ade).getContent(), null, 0);
		}
	}
	
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #10
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 #11
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 #12
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 CityJSON builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityJSONBuilder builder = ctx.createCityJSONBuilder();

	System.out.println(df.format(new Date()) + "reading only city furniture objects from CityJSON file LOD3_Railway.json");
	CityJSONInputFactory in = builder.createCityJSONInputFactory();

	CityJSONReader reader = in.createCityJSONReader(new File("datasets/LOD3_Railway.json"));
	reader = in.createFilteredCityJSONReader(reader, new CityObjectTypeFilter() {

		// return true if you want to consume the CityJSON feature of the given "type"
		public boolean accept(String type) {
			return type.equals("CityFurniture");
		}
	});

	CityModel cityModel = reader.read();
	reader.close();
	
	// iterate over all city objects of the city model
	for (CityObjectMember member : cityModel.getCityObjectMember()) {
		if (member.isSetCityObject()) {
			AbstractCityObject cityObject = member.getCityObject();
			System.out.println("Found " + cityObject.getCityGMLClass() + " feature");
			System.out.println("\tgml:id '" + cityObject.getId() + "'");
			
			// check and print LoD geometries
			LodRepresentation lods = cityObject.getLodRepresentation();
			for (int lod = 0; lod < 5; lod++) {
				if (lods.isSetGeometry(lod))
					System.out.println("\thas LoD " + lod + " geometry");
			}
		}
	}
	
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #13
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 #14
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 #15
Source File: ObjectTreeValidation.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();
	
	// creating example (and simple) CityGML object tree
	System.out.println(df.format(new Date()) + "creating simple city model with invalid content");
	Building building = new Building();
	
	// set invalid gml:id
	building.setId("1st-Building");
	
	// set empty and thus invalid generic attribute set
	building.addGenericAttribute(new GenericAttributeSet());
	
	CityModel cityModel = new CityModel();
	cityModel.addCityObjectMember(new CityObjectMember(building));
	
	System.out.println(df.format(new Date()) + "creating citygml4j Validator and validating city model against CityGML 2.0.0");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	Validator validator = builder.createValidator(schemaHandler);
	
	validator.setValidationEventHandler(new ValidationEventHandler() {			
		public boolean handleEvent(ValidationEvent event) {
			System.out.println(event.getMessage());
			return true;
		}
	});		
	
	validator.validate(cityModel, CityGMLVersion.v2_0_0);
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #16
Source File: SimpleReader.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 LOD2_Buildings_v100.gml completely into main memory");
	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_Buildings_v100.gml"));
	
	while (reader.hasNext()) {
		CityGML citygml = reader.nextFeature();

		if (citygml.getCityGMLClass() == CityGMLClass.CITY_MODEL) {
			CityModel cityModel = (CityModel)citygml;

			System.out.println(df.format(new Date()) + "Found " + citygml.getCityGMLClass() + " version " + cityModel.getModule().getVersion());
			System.out.println(df.format(new Date()) + "going through city model and counting building instances");

			int count = 0;
			for (CityObjectMember cityObjectMember : cityModel.getCityObjectMember()) {
				AbstractCityObject cityObject = cityObjectMember.getCityObject();
				if (cityObject.getCityGMLClass() == CityGMLClass.BUILDING)
					count++;
			}

			System.out.println(df.format(new Date()) + "The city model contains " + count + " building features");
		}	
	}			
	
	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #17
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 #18
Source File: FeatureFunctionWalker.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public FeatureFunctionWalker() {
	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		for (ADEContext adeContext : CityGMLContext.getInstance().getADEContexts())
			useADEWalker(adeContext.createDefaultFeatureFunctionWalker());
	}
}
 
Example #19
Source File: FeatureWalker.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public FeatureWalker() {
	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		for (ADEContext adeContext : CityGMLContext.getInstance().getADEContexts())
			useADEWalker(adeContext.createDefaultFeatureWalker());
	}
}
 
Example #20
Source File: GMLWalker.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public GMLWalker() {
	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		for (ADEContext adeContext : CityGMLContext.getInstance().getADEContexts())
			useADEWalker(adeContext.createDefaultGMLWalker());
	}
}
 
Example #21
Source File: GMLFunctionWalker.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public GMLFunctionWalker() {
	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		for (ADEContext adeContext : CityGMLContext.getInstance().getADEContexts())
			useADEWalker(adeContext.createDefaultGMLFunctionWalker());
	}
}
 
Example #22
Source File: SchemaHandler.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static synchronized SchemaHandler newInstance() throws SAXException {
	if (instance == null) {
		instance = new SchemaHandler();

		URL schemaURL = SchemaHandler.class.getResource("/org/citygml4j/schemas/citygml4j.xsd");
		if (schemaURL == null)
			throw new SAXException("Failed to parse CityGML schemas. Could not find '/org/citygml4j/schemas/citygml4j.xsd' on classpath.");

		instance.parse(schemaURL.toString());
	}

	SchemaHandler schemaHandler = new SchemaHandler();
	schemaHandler.schemaSets.addAll(instance.schemaSets);
	schemaHandler.visited.putAll(instance.visited);

	// CityGML 0.4.0
	schemaHandler.schemaLocations.put("http://www.citygml.org/citygml/1/0/0", CityGMLContext.class.getResource("/org/citygml4j/schemas/citygml/0.4.0/CityGML.xsd").toString());

	// parse local schemas provided by ADE modules
	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		for (ADEContext adeContext : CityGMLContext.getInstance().getADEContexts()) {
			for (ADEModule adeModule : adeContext.getADEModules()) {
				URL schemaResource = adeModule.getSchemaResource();
				if (schemaResource != null) {
					try {
						schemaHandler.parse(schemaResource.toURI().toString());
					} catch (URISyntaxException e) {
						throw new SAXException("Failed to parse XML schema file for ADE namespace '" + adeModule.getNamespaceURI() + "'.", e);
					}
				}
			}
		}
	}

	return schemaHandler;
}
 
Example #23
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 #24
Source File: ApplyXSLTWhenReading.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();

	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	CityModel cityModel = null;
	Building building = null;

	// first step: we read the dataset as is without applying an XSLT stylesheet
	System.out.println(df.format(new Date()) + "1st step: read the CityGML file LOD2_Buildings_v100.gml 'as is'");
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_Building_v100.gml"));

	cityModel = (CityModel)reader.nextFeature();
	building = (Building)cityModel.getCityObjectMember().get(0).getCityObject();
	System.out.println(df.format(new Date()) + "Building has address information: " + building.isSetAddress());
	reader.close();

	// second step: we read the dataset again but this time we apply an XSLT stlyesheet
	// you can pass one or more XSLT stylesheets to a CityGMLInputFactory. The stylesheets
	// are applied before reading the data. If you provide more than one stylesheet,
	// the stylesheets are automatically chained, i.e., the output of the first one is taken as input
	// for the second one, and so on. The order in which you pass the stylesheets to the CityGMLInputFactory
	// is therefore important.

	// Note: If you parse the document chunk-wise, make sure that your XSLT 
	// transformations use a local scope that matches the chunks. 

	// In this example, the stylesheet simply removes the xAL address data from the building
	System.out.println(df.format(new Date()) + "2nd step: let's read the dataset again and apply the XSLT stylesheet RemoveAddress.xsl");
	SAXTransformerFactory factory = (SAXTransformerFactory)TransformerFactory.newInstance();
	Templates stylesheet = factory.newTemplates(new StreamSource(new File("datasets/stylesheets/RemoveAddress.xsl")));
	in.setTransformationTemplates(stylesheet);

	reader = in.createCityGMLReader(new File("datasets/LOD2_Building_v100.gml"));

	cityModel = (CityModel)reader.nextFeature();
	building = (Building)cityModel.getCityObjectMember().get(0).getCityObject();
	System.out.println(df.format(new Date()) + "Building has address information: " + building.isSetAddress());
	reader.close();

	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #25
Source File: AccessingParentElements.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();

	System.out.println(df.format(new Date()) + "reading CityGML file LOD2_Building_v100.gml");
	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_Building_v100.gml"));

	CityModel cityModel = (CityModel)reader.nextFeature();
	reader.close();
	
	System.out.println(df.format(new Date()) + "retrieving object with gml:id UUID_08371879-bde6-4ba6-9fc6-088ee2ce1913");
	XLinkResolver resolver = new XLinkResolver();
	AbstractGeometry geometry = resolver.getGeometry("UUID_08371879-bde6-4ba6-9fc6-088ee2ce1913", cityModel);
	System.out.println("gml:id 'UUID_08371879-bde6-4ba6-9fc6-088ee2ce1913' belongs to: " + geometry.getGMLClass());

	System.out.println(df.format(new Date()) + "retrieving direct and transitive parents");			
	ChildInfo info = new ChildInfo();
	
	System.out.println("Direct parent XML element: " + ((GML)geometry.getParent()).getGMLClass());
	
	AbstractGeometry parentGeometry = info.getParentGeometry(geometry);
	System.out.println("Direct parent geometry: " + parentGeometry.getGMLClass()
			+ ", gml:id='" + parentGeometry.getId() + "'");
	
	AbstractCityObject parentCityObject = info.getParentCityObject(geometry);
	System.out.println("Direct parent CityObject: " + parentCityObject.getCityGMLClass()
			+ ", gml:id='" + parentCityObject.getId() + "'");
	
	Building parentCityObjectByType = info.getParentCityObject(geometry, Building.class);
	System.out.println("Transitive parent CityObject of type Building: " + parentCityObjectByType.getCityGMLClass()
			+ ", gml:id='" + parentCityObjectByType.getId() + "'");

	LandUse noParent = info.getParentCityObject(geometry, LandUse.class);
	System.out.println("Transitive parent CityObject of type LandUse: " + noParent);

	AbstractCityObject rootCityObject = info.getRootCityObject(geometry);
	System.out.println("Root CityObject: " + rootCityObject.getCityGMLClass()
			+ ", gml:id='" + rootCityObject.getId() + "'");
	
	CityGML rootFeature = info.getRootCityGML(geometry);
	System.out.println("Root CityGML instance: " + rootFeature.getCityGMLClass());
	
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #26
Source File: ResolvingInternalXlinks.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();

	System.out.println(df.format(new Date()) + "reading CityGML file LOD2_CityObjectGroup_v100.gml");
	CityGMLInputFactory in = builder.createCityGMLInputFactory();
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_CityObjectGroup_v100.gml"));

	CityModel cityModel = (CityModel)reader.nextFeature();
	reader.close();
	
	System.out.println(df.format(new Date()) + "creating XLinkResolver");
	XLinkResolver xLinkResolver = new XLinkResolver();
	
	for (CityObjectMember member : cityModel.getCityObjectMember()) {
		if (member.isSetCityObject() && 
				member.getCityObject().getCityGMLClass() == CityGMLClass.CITY_OBJECT_GROUP) {
			CityObjectGroup group = (CityObjectGroup)member.getCityObject();
			
			for (CityObjectGroupMember groupMember : group.getGroupMember()) {
				System.out.println(df.format(new Date()) + "processing group member with role: " + groupMember.getGroupRole());					
				System.out.println(df.format(new Date()) + "resolving XLink to " + groupMember.getHref());
				AbstractCityObject cityObject = xLinkResolver.getAbstractGML(groupMember.getHref(), cityModel, AbstractCityObject.class);
				System.out.println("   Referenced city object: " + cityObject.getCityGMLClass() + 
						", gml:id='" + cityObject.getId() +"'");
				 
				if (cityObject.getId().equals("ID_76")) {
					Road road = (Road)cityObject;
					TrafficArea trafficArea = road.getTrafficArea().get(2).getTrafficArea();
					
					System.out.println(df.format(new Date()) + "resolving XLink to " + trafficArea.getLod2MultiSurface().getHref());
					ModelObject object = xLinkResolver.getObject(trafficArea.getLod2MultiSurface().getHref(), road);
					if (object instanceof MultiSurface) {
						MultiSurface multiSurface = (MultiSurface)object;
						System.out.println("   Referenced geometry: " + multiSurface.getGMLClass() + 
								", gml:id='" + multiSurface.getId() + "'");
					}
				}
			}
		}
	}
	
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #27
Source File: DOMAndXPath.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();

	System.out.println(df.format(new Date()) + "creating citygml4j JAXBUnmarshaller and JAXBMarshaller instances");
	JAXBUnmarshaller unmarshaller = builder.createJAXBUnmarshaller();
	JAXBMarshaller marshaller = builder.createJAXBMarshaller();
	marshaller.setModuleContext(new ModuleContext(CityGMLVersion.v2_0_0));
	
	// create DOM model from CityGML document
	System.out.println(df.format(new Date()) + "reading CityGML file LOD2_Building_with_Placeholder_v200.gml as DOM tree");
	DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
	docFactory.setNamespaceAware(true);		
	DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
	Document document = docBuilder.parse("datasets/LOD2_Building_with_Placeholder_v200.gml");

	// create XPath factory
	System.out.println(df.format(new Date()) + "creating XPath factory");
	XPathFactory xpathFactory = XPathFactory.newInstance();
	XPath xpath = xpathFactory.newXPath();

	// get CityGML namespace context
	CityGMLNamespaceContext nsContext = new CityGMLNamespaceContext();
	nsContext.setPrefixes(CityGMLVersion.v2_0_0);
	xpath.setNamespaceContext(nsContext);

	// first: retrieve building node using XPath
	System.out.println(df.format(new Date()) + "searching for bldg:Building node in DOM tree using an XPath expression");
	Node buildingNode = (Node)xpath.evaluate("//bldg:Building", document, XPathConstants.NODE);

	// unmarshal DOM node to citygml4j
	System.out.println(df.format(new Date()) + "unmarshalling DOM node to citygml4j");
	Building building = (Building)unmarshaller.unmarshal(buildingNode);

	// add gml:id and gml:description to building
	System.out.println(df.format(new Date()) + "processing content using citygml4j");
	building.setId(DefaultGMLIdManager.getInstance().generateUUID());
	StringOrRef description = new StringOrRef();
	description.setValue("processed by citygml4j using DOM and XPath");
	building.setDescription(description);

	// marshal to DOM and put into document
	System.out.println(df.format(new Date()) + "marshalling back to DOM");
	Element newBuildingNode = marshaller.marshalDOMElement(building, document);
	buildingNode.getParentNode().replaceChild(newBuildingNode, buildingNode);
	
	// second: get placeholder using XPath
	System.out.println(df.format(new Date()) + "searching for 'Placeholder' in DOM tree using an XPath expression");
	Node memberNode = (Node)xpath.evaluate("//core:cityObjectMember[comment()='Placeholder']", document, XPathConstants.NODE);

	// create simple citygml4j object to insert into placeholder
	System.out.println(df.format(new Date()) + "inserting CityFurniture instance at placeholder using citygml4j");
	CityFurniture cityFurniture = new CityFurniture();
	cityFurniture.setDescription(description);		
	CityObjectMember member = new CityObjectMember(cityFurniture);

	// marshal to DOM and put into document
	System.out.println(df.format(new Date()) + "marshalling back to DOM");
	Element newMemberNode = marshaller.marshalDOMElement(member, document);
	memberNode.getParentNode().replaceChild(newMemberNode, memberNode);
	
	// write DOM to file
	System.out.println(df.format(new Date()) + "writing DOM tree");
	Files.createDirectories(Paths.get("output"));

	TransformerFactory transFactory = TransformerFactory.newInstance();
	Transformer trans = transFactory.newTransformer();
	DOMSource source = new DOMSource(document);

	try (SAXWriter saxWriter = new SAXWriter(new FileOutputStream("output/LOD2_DOM_result_v200.gml"), "UTF-8")) {
		saxWriter.setIndentString("  ");
		saxWriter.setNamespaceContext(nsContext);
		trans.transform(source, new SAXResult(saxWriter));
	}

	System.out.println(df.format(new Date()) + "CityGML file LOD2_DOM_result_v200.gml written");
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #28
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");
}
 
Example #29
Source File: Serialization.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();

    System.out.println(df.format(new Date()) + "reading CityGML file LOD3_Railway_v200.gml into main memory");
    CityGMLInputFactory in = builder.createCityGMLInputFactory();

    CityModel cityModel;
    try (CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD3_Railway_v200.gml"))) {
        cityModel = (CityModel) reader.nextFeature();
    }

    // serialize the object tree
    System.out.println(df.format(new Date()) + "serializing in-memory citygml4j object tree to file out.ser");
    Files.createDirectories(Paths.get("output"));

    // create an ObjectOutputStream to serialize the CityModel
    // make sure to use a BufferedOutputStream for performance reasons
    // to keep the file size small, consider using a GZIPOutputStream in addition
    try (ObjectOutputStream stream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("output/out.ser")))) {
        stream.writeObject(cityModel);
    }

    System.out.println(df.format(new Date()) + "citygml4j object tree successfully serialized");

    // let's read the serialized object tree back into main memory
    System.out.println(df.format(new Date()) + "deserializing out.ser back into main memory");

    // create an ObjectInputStream to deserialize the CityModel
    // again, make sure to use a BufferedInputStream for performance reasons
    try (ObjectInputStream stream = new ObjectInputStream(new BufferedInputStream(new FileInputStream("output/out.ser")))) {
        Object o = stream.readObject();

        if (o instanceof CityModel) {
            System.out.println(df.format(new Date()) + "successfully read citygml4j object tree from file out.ser");
            cityModel = (CityModel) o;

            System.out.println(df.format(new Date()) + "Found the following cityObjectMembers in out.ser:");
            EnumMap<CityGMLClass, Integer> features = new EnumMap<>(CityGMLClass.class);
            cityModel.getCityObjectMember().forEach(m -> features.merge(m.getCityObject().getCityGMLClass(), 1, Integer::sum));
            features.forEach((key, value) -> System.out.println(key + ": " + value));
        } else
            throw new CityGMLReadException("Failed to deserialize the file out.ser");
    }

    System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #30
Source File: JAXBContextPath.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
private static StringJoiner buildContextPath() {
	StringJoiner joiner = new StringJoiner(":");

	// CityGML 2.0
	joiner.add("net.opengis.citygml._2");
	joiner.add("net.opengis.citygml.appearance._2");
	joiner.add("net.opengis.citygml.bridge._2");
	joiner.add("net.opengis.citygml.building._2");
	joiner.add("net.opengis.citygml.cityfurniture._2");
	joiner.add("net.opengis.citygml.cityobjectgroup._2");
	joiner.add("net.opengis.citygml.generics._2");
	joiner.add("net.opengis.citygml.landuse._2");
	joiner.add("net.opengis.citygml.relief._2");
	joiner.add("net.opengis.citygml.texturedsurface._2");
	joiner.add("net.opengis.citygml.transportation._2");
	joiner.add("net.opengis.citygml.tunnel._2");
	joiner.add("net.opengis.citygml.vegetation._2");
	joiner.add("net.opengis.citygml.waterbody._2");

	// CityGML 1.0
	joiner.add("net.opengis.citygml._1");
	joiner.add("net.opengis.citygml.appearance._1");
	joiner.add("net.opengis.citygml.building._1");
	joiner.add("net.opengis.citygml.cityfurniture._1");
	joiner.add("net.opengis.citygml.cityobjectgroup._1");
	joiner.add("net.opengis.citygml.generics._1");
	joiner.add("net.opengis.citygml.landuse._1");
	joiner.add("net.opengis.citygml.relief._1");
	joiner.add("net.opengis.citygml.texturedsurface._1");
	joiner.add("net.opengis.citygml.transportation._1");
	joiner.add("net.opengis.citygml.vegetation._1");
	joiner.add("net.opengis.citygml.waterbody._1");

	// GML 3.1.1 and xAL 2.0
	joiner.add("net.opengis.gml");
	joiner.add("oasis.names.tc.ciq.xsdschema.xal._2");

	// ADE context paths
	CityGMLContext context = CityGMLContext.getInstance();
	if (context.hasADEContexts()) {
		for (ADEContext adeContext : CityGMLContext.getInstance().getADEContexts()) {
			for (ADEModule module : adeContext.getADEModules()) {
				for (String contextPath : module.getJAXBPackageNames())
					joiner.add(contextPath);
			}
		}
	}

	return joiner;
}