org.citygml4j.model.module.Modules Java Examples

The following examples show how to use org.citygml4j.model.module.Modules. 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: XMLElementChecker.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
private List<QName> prepareNameList(List<QName> nameList, boolean checkFeature) {
	List<QName> result = new ArrayList<>();

	for (QName name : nameList) {
		if (name.getNamespaceURI().length() != 0)
			result.add(name);
		else {
			for (Module module : Modules.getModules()) {
				if ((checkFeature && module.hasFeature(name.getLocalPart()))
						|| (!checkFeature && module.hasFeatureProperty(name.getLocalPart())))
					result.add(new QName(module.getNamespaceURI(), name.getLocalPart()));
			}
		}
	}

	return result;
}
 
Example #3
Source File: CityGMLUnmarshaller.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
private CityGMLModule getCityGMLModule(Object src) {
	if (src != null) {
		moduleMatcher.reset(src.getClass().getPackage().getName());
		
		if (moduleMatcher.matches()) {
			String moduleString = moduleMatcher.group(1);
			if (moduleString == null)
				moduleString = "core";
			
			CityGMLModuleVersion version = moduleMatcher.group(2).equals("_2") ? CityGMLModuleVersion.v2_0_0 : CityGMLModuleVersion.v1_0_0;
			for (CityGMLModule module : Modules.getCityGMLModules()) {
				if (module.getVersion() == version && module.getType().toString().toLowerCase().equals(moduleString))
					return module;
			}	
		}
	}

	return null;
}
 
Example #4
Source File: CoreUnmarshaller.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
private boolean satisfiesCityGMLNameFilter(AbstractFeature cityObject) {
	boolean accept = false;

	for (Module module : Modules.getModules()) {
		if (!(module instanceof CityGMLModule) && !(module instanceof ADEModule))
			continue;

		QName name = module.getFeatureName(cityObject.getClass());
		if (name != null && json.getCityGMLNameFilter().accept(name)) {
			accept = true;
			break;
		}
	}

	return accept;
}
 
Example #5
Source File: FeatureTypes.java    From web-feature-service with Apache License 2.0 5 votes vote down vote up
public Set<Module> getModules() {
	Set<Module> result = new HashSet<>();
	for (QName name : getFeatureTypes().keySet())
		result.add(Modules.getModule(name.getNamespaceURI()));

	return result;
}
 
Example #6
Source File: ProjectionFilter.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
public boolean containsProperty(String name, String namespaceURI) {
	if (properties == null && genericAttributes == null)
		return TRUE;

	if (properties != null) {
		for (AbstractProperty property : properties) {
			if (property.getPath().equals(name) 
					&& property.isSetSchema()
					&& property.getSchema().matchesNamespaceURI(namespaceURI))
				return TRUE;
		}
	}

	if (genericAttributes != null) {
		boolean isGenericAttribute = false;
		for (CityGMLModule module : Modules.getCityGMLModules(CityGMLModuleType.GENERICS)) {
			if (module.getNamespaceURI().equals(namespaceURI)) {
				isGenericAttribute = true;
				break;
			}
		}

		if (isGenericAttribute) {
			for (GenericAttribute genericAttribute : genericAttributes) {					
				String attrName = getGenericAttributeName(genericAttribute.getType());
				if (name.equals(attrName))
					return TRUE;
			}
		}
	}

	return FALSE;
}
 
Example #7
Source File: CityGMLContext.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void unregisterADEContext(ADEContext adeContext) {
	for (ADEModule module : adeContext.getADEModules())
		Modules.unregisterADEModule(module);

	if (adeContext instanceof CityJSONExtensionContext)
		unregisterCityJSONExtension(((CityJSONExtensionContext) adeContext).getCityJSONExtension());

	adeContexts.remove(adeContext);
}
 
Example #8
Source File: SchemaHandler.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public boolean registerSchemaLocation(String namespaceURI, File schemaLocation) {
	if (Modules.getModule(namespaceURI) != null)
		return false;

	// CityGML 0.4.0
	if ("http://www.citygml.org/citygml/1/0/0".equals(namespaceURI))
		return false;

	schemaLocations.put(namespaceURI, schemaLocation.toURI().toString());
	return true;
}
 
Example #9
Source File: XMLElementChecker.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
private ElementInfo getFeature(QName name) {
	ElementInfo elementInfo = null;
	String localName = name.getLocalPart();
	String namespaceURI = name.getNamespaceURI();

	Module module = Modules.getModule(namespaceURI);
	if (module != null) {
		Class<? extends AbstractFeature> featureClass = module.getFeatureClass(localName);

		if (featureClass != null) {
			elementInfo = new ElementInfo();
			elementInfo.isFeature = true;
			elementInfo.featureClass = featureClass;

			if (module instanceof ADEModule) {
				Schema schema = schemaHandler.getSchema(namespaceURI);
				if (schema != null)
					elementInfo.elementDecl = schema.getGlobalElementDecl(localName);
			}

			if (excludes != null) {
				List<String> localNames = excludes.get(namespaceURI);
				if (localNames != null && localNames.contains(localName))
					elementInfo.isFeature = false;
			}				
		}
	}

	return elementInfo;
}
 
Example #10
Source File: XMLElementChecker.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
private ElementInfo getCityGMLFeatureProperty(QName name) {
	ElementInfo elementInfo = null;
	String localName = name.getLocalPart();
	String namespaceURI = name.getNamespaceURI();

	boolean isFeatureProperty = false;
	boolean skipNestedElements = false;

	if (featureReadMode == FeatureReadMode.SPLIT_PER_COLLECTION_MEMBER) {
		HashSet<String> properties = cityGMLFeatureProperties.get(namespaceURI);
		isFeatureProperty = properties != null && properties.contains(localName);
	} else {
		Module module = Modules.getModule(namespaceURI);
		if (module instanceof CityGMLModule) {
			CityGMLModule cityGMLModule = (CityGMLModule)module;
			isFeatureProperty = cityGMLModule.hasFeatureProperty(localName);					
			if (localName.equals("appearance"))
				skipNestedElements = keepInlineAppearance;
		}
	}

	if (isFeatureProperty) {
		elementInfo = new ElementInfo();
		elementInfo.isFeatureProperty = true;
		elementInfo.hasXLink = true;
		elementInfo.skipNestedElements = skipNestedElements;
	}

	return elementInfo;
}
 
Example #11
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 #12
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 #13
Source File: FeatureSplitter.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AbstractFeature feature) {
	if (!excludes.isEmpty())
		for (Class<? extends CityGML> exclude : excludes)
			if (exclude.isInstance(feature))
				return;

	ModelObject parent = feature.getParent();
	boolean addToResult = false;

	if (splitMode == FeatureSplitMode.SPLIT_PER_COLLECTION_MEMBER && feature instanceof ADEModelObject) {
		boolean accept = false;
		
		for (ADEModule module : Modules.getADEModules()) {
			if (module.getFeatureName(feature.getClass()) != null) {
				accept = true;
				break;
			}
		}
		
		if (!accept) {
			super.visit(feature);
			return;
		}
	}
				
	if (parent != null) {
		if (parent instanceof FeatureProperty<?>) {
			FeatureProperty<?> property = (FeatureProperty<?>)parent;				
			property.setHref('#' + getAndSetGmlId(feature));
			property.unsetFeature();
			addToResult = true;
		}

		else if (parent instanceof FeatureArrayProperty) {
			FeatureArrayProperty featureArray = (FeatureArrayProperty)parent;
			featureArray.unsetFeature(feature);
			addToResult = true;
		}

	} else
		addToResult = true;

	if (addToResult && feature instanceof CityGML)
		result.add((CityGML)feature);	

	super.visit(feature);
}
 
Example #14
Source File: CityGMLMarshaller.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
private CityGMLModule getCityGMLModule(Object src) {

		if (src instanceof ModelObject) {
			ModuleContext moduleContext = jaxb.getModuleContext();

			if (src instanceof AppearanceModuleComponent)
				return (AppearanceModule)moduleContext.getModule(CityGMLModuleType.APPEARANCE);
			else if (src instanceof BridgeModuleComponent)
				return (BridgeModule)moduleContext.getModule(CityGMLModuleType.BRIDGE);
			else if (src instanceof BuildingModuleComponent)
				return (BuildingModule)moduleContext.getModule(CityGMLModuleType.BUILDING);
			else if (src instanceof CityFurnitureModuleComponent)
				return (CityFurnitureModule)moduleContext.getModule(CityGMLModuleType.CITY_FURNITURE);
			else if (src instanceof CityObjectGroupModuleComponent)
				return (CityObjectGroupModule)moduleContext.getModule(CityGMLModuleType.CITY_OBJECT_GROUP);
			else if (src instanceof GenericsModuleComponent)
				return (GenericsModule)moduleContext.getModule(CityGMLModuleType.GENERICS);
			else if (src instanceof LandUseModuleComponent)
				return (LandUseModule)moduleContext.getModule(CityGMLModuleType.LAND_USE);
			else if (src instanceof ReliefModuleComponent)
				return (ReliefModule)moduleContext.getModule(CityGMLModuleType.RELIEF);
			else if (src instanceof TexturedSurfaceModuleComponent)
				return (TexturedSurfaceModule)moduleContext.getModule(CityGMLModuleType.TEXTURED_SURFACE);
			else if (src instanceof TransportationModuleComponent)
				return (TransportationModule)moduleContext.getModule(CityGMLModuleType.TRANSPORTATION);
			else if (src instanceof TunnelModuleComponent)
				return (TunnelModule)moduleContext.getModule(CityGMLModuleType.TUNNEL);
			else if (src instanceof VegetationModuleComponent)
				return (VegetationModule)moduleContext.getModule(CityGMLModuleType.VEGETATION);
			else if (src instanceof WaterBodyModuleComponent)
				return (WaterBodyModule)moduleContext.getModule(CityGMLModuleType.WATER_BODY);
			else
				return (CoreModule)moduleContext.getModule(CityGMLModuleType.CORE);		
		}

		else if (src != null) {
			moduleMatcher.reset(src.getClass().getPackage().getName());

			if (moduleMatcher.matches()) {
				String moduleString = moduleMatcher.group(1);
				if (moduleString == null)
					moduleString = "core";

				CityGMLModuleVersion version = moduleMatcher.group(2).equals("_2") ? CityGMLModuleVersion.v2_0_0 : CityGMLModuleVersion.v1_0_0;
				for (CityGMLModule module : Modules.getCityGMLModules()) {
					if (module.getVersion() == version && module.getType().toString().toLowerCase().equals(moduleString))
						return module;
				}	
			}		
		}

		return null;
	}