📄 getfeature.java
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.geoserver.wfs;
import net.opengis.wfs.AllSomeType;
import net.opengis.wfs.FeatureCollectionType;
import net.opengis.wfs.GetFeatureType;
import net.opengis.wfs.GetFeatureWithLockType;
import net.opengis.wfs.LockFeatureResponseType;
import net.opengis.wfs.LockFeatureType;
import net.opengis.wfs.LockType;
import net.opengis.wfs.QueryType;
import net.opengis.wfs.WfsFactory;
import org.geotools.data.DataUtilities;
import org.geotools.data.DefaultQuery;
import org.geotools.data.FeatureSource;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.GeoTools;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureType;
import org.geotools.feature.GeometryAttributeType;
import org.geotools.feature.SchemaException;
import org.geotools.filter.expression.AbstractExpressionVisitor;
import org.geotools.filter.visitor.AbstractFilterVisitor;
import org.geotools.referencing.CRS;
import org.geotools.referencing.factory.GeotoolsFactory;
import org.geotools.xml.EMFUtils;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.expression.ExpressionVisitor;
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.sort.SortBy;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.vfny.geoserver.global.AttributeTypeInfo;
import org.vfny.geoserver.global.Data;
import org.vfny.geoserver.global.FeatureTypeInfo;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
/**
* Web Feature Service GetFeature operation.
* <p>
* This operation returns an array of {@link org.geotools.feature.FeatureCollection}
* instances.
* </p>
*
* @author Rob Hranac, TOPP
* @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
*
* @version $Id: GetFeature.java 7746 2007-11-13 15:38:35Z aaime $
*/
public class GetFeature {
/** Standard logging instance for class */
private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.vfny.geoserver.requests");
/** The catalog */
protected Data catalog;
/** The wfs configuration */
protected WFS wfs;
/** filter factory */
protected FilterFactory filterFactory;
/**
* Creates the GetFeature operation.
*
*/
public GetFeature(WFS wfs, Data catalog) {
this.wfs = wfs;
this.catalog = catalog;
}
/**
* @return The reference to the GeoServer catalog.
*/
public Data getCatalog() {
return catalog;
}
/**
* @return The reference to the WFS configuration.
*/
public WFS getWFS() {
return wfs;
}
/**
* Sets the filter factory to use to create filters.
*
* @param filterFactory
*/
public void setFilterFactory(FilterFactory filterFactory) {
this.filterFactory = filterFactory;
}
public FeatureCollectionType run(GetFeatureType request)
throws WFSException {
List queries = request.getQuery();
if (queries.isEmpty()) {
throw new WFSException("No query specified");
}
if (EMFUtils.isUnset(queries, "typeName")) {
String msg = "No feature types specified";
throw new WFSException(msg);
}
// Optimization Idea
//
// We should be able to reduce this to a two pass opperations.
//
// Pass #1 execute
// - Attempt to Locks Fids during the first pass
// - Also collect Bounds information during the first pass
//
// Pass #2 writeTo
// - Using the Bounds to describe our FeatureCollections
// - Iterate through FeatureResults producing GML
//
// And allways remember to release locks if we are failing:
// - if we fail to aquire all the locks we will need to fail and
// itterate through the the FeatureSources to release the locks
//
if (request.getMaxFeatures() == null) {
request.setMaxFeatures(BigInteger.valueOf(Integer.MAX_VALUE));
}
// take into consideration the wfs max features
int maxFeatures = Math.min(request.getMaxFeatures().intValue(),
wfs.getGeoServer().getMaxFeatures());
FeatureCollectionType result = WfsFactory.eINSTANCE.createFeatureCollectionType();
int count = 0; //should probably be long
try {
for (int i = 0; (i < request.getQuery().size()) && (count <= maxFeatures); i++) {
QueryType query = (QueryType) request.getQuery().get(i);
FeatureTypeInfo meta = null;
if (query.getTypeName().size() == 1) {
meta = featureTypeInfo((QName) query.getTypeName().get(0));
} else {
//TODO: a join is taking place
}
FeatureSource source = meta.getFeatureSource();
List atts = meta.getAttributes();
List attNames = meta.getAttributeNames();
//make sure property names are cool
List propNames = query.getPropertyName();
for (Iterator iter = propNames.iterator(); iter.hasNext();) {
String propName = (String) iter.next();
//HACK: strip off namespace
if (propName.indexOf(':') != -1) {
propName = propName.substring(propName.indexOf(':') + 1);
}
if (!attNames.contains(propName)) {
String mesg = "Requested property: " + propName + " is " + "not available "
+ "for " + query.getTypeName() + ". " + "The possible propertyName "
+ "values are: " + attNames;
throw new WFSException(mesg);
}
}
//we must also include any properties that are mandatory ( even if not requested ),
// ie. those with minOccurs > 0
List extraGeometries = new ArrayList();
List properties = new ArrayList();
if (propNames.size() != 0) {
Iterator ii = atts.iterator();
while (ii.hasNext()) {
AttributeTypeInfo ati = (AttributeTypeInfo) ii.next();
LOGGER.finer("checking to see if " + propNames + " contains" + ati);
if (((ati.getMinOccurs() > 0) && (ati.getMaxOccurs() != 0))) {
//mandatory, add it
properties.add(ati.getName());
continue;
}
//check if it was requested
for (Iterator p = propNames.iterator(); p.hasNext();) {
String propName = (String) p.next();
if (propName.matches("(\\w+:)?" + ati.getName())) {
properties.add(ati.getName());
break;
}
}
// if we need to force feature bounds computation, we have to load
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -