public Object get(Object object, String xpath, Class target) { if ( object instanceof Feature ) { return ((Feature) object).getDefaultGeometry(); } if ( object instanceof FeatureType ) { return ((FeatureType)object).getDefaultGeometry(); } return null; }
private static FeatureType forceType( FeatureType startingType, CoordinateReferenceSystem forcedCS, boolean forceOnlyMissing ) throws SchemaException{ if (forcedCS == null) { throw new NullPointerException("CoordinateSystem required"); } CoordinateReferenceSystem originalCs = startingType.getDefaultGeometry() != null ? startingType.getDefaultGeometry().getCoordinateSystem() : null; if (forcedCS.equals(originalCs)) { return startingType; } else { return FeatureTypes.transform(startingType, forcedCS, forceOnlyMissing); } }
private static FeatureType forceType( FeatureType startingType, CoordinateReferenceSystem forcedCS ) throws SchemaException{ if (forcedCS == null) { throw new NullPointerException("CoordinateSystem required"); } CoordinateReferenceSystem originalCs = startingType.getDefaultGeometry().getCoordinateSystem(); if (forcedCS.equals(originalCs)) { return startingType; } else { return FeatureTypes.transform(startingType, forcedCS); } }
public ReprojectFeatureIterator(FeatureIterator reader, FeatureType schema, MathTransform transform) { this.reader = reader; this.schema = schema; transformer.setMathTransform((MathTransform2D)transform); //set hte target coordinate system if ( schema.getDefaultGeometry() != null ) { transformer.setCoordinateReferenceSystem(schema.getDefaultGeometry().getCoordinateSystem()); } }
public ReprojectingFeatureCollection(FeatureCollection delegate, CoordinateReferenceSystem target) { this( delegate, delegate.getSchema().getDefaultGeometry().getCoordinateSystem(), target ); }
/** * Builds a new ForceCoordinateSystemFeatureReader * * @param reader * @param cs * * @throws SchemaException * @throws NullPointerException DOCUMENT ME! * @throws IllegalArgumentException DOCUMENT ME! */ public ForceCoordinateSystemIterator(FeatureIterator reader, FeatureType type, CoordinateReferenceSystem cs) throws SchemaException { if (cs == null) { throw new NullPointerException("CoordinateSystem required"); } CoordinateReferenceSystem originalCs = type.getDefaultGeometry() .getCoordinateSystem(); if (cs.equals(originalCs)) { schema = FeatureTypes.transform(type, cs); } this.reader = reader; }
protected boolean isDefaultGeometry(AttributeExpression ae) { return reader.getFeatureType().getDefaultGeometry().getName().equals(ae.getAttributePath()); }
/** * Builds a new ForceCoordinateSystemFeatureReader * * @param reader * @param cs * * @throws SchemaException * @throws NullPointerException DOCUMENT ME! * @throws IllegalArgumentException DOCUMENT ME! */ public ForceCoordinateSystemFeatureReader(FeatureReader reader, CoordinateReferenceSystem cs, boolean forceOnlyMissing) throws SchemaException { if (cs == null) { throw new NullPointerException("CoordinateSystem required"); } FeatureType type = reader.getFeatureType(); CoordinateReferenceSystem originalCs = type.getDefaultGeometry() .getCoordinateSystem(); if (!cs.equals(originalCs)) { schema = FeatureTypes.transform(type, cs, forceOnlyMissing); } this.reader = reader; }
public ReferencedEnvelope getBounds() { CoordinateReferenceSystem sourceCrs = featureSource.getSchema().getDefaultGeometry() .getCoordinateSystem(); ReferencedEnvelope env; try { env = new ReferencedEnvelope(featureSource.getBounds(), sourceCrs); return env; } catch (MismatchedDimensionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } // ------------------------------------------------------------------------
public ReprojectFeatureReader(FeatureReader reader, CoordinateReferenceSystem cs) throws SchemaException, OperationNotFoundException, NoSuchElementException, FactoryException{ if (cs == null) { throw new NullPointerException("CoordinateSystem required"); } FeatureType type = reader.getFeatureType(); CoordinateReferenceSystem original = type.getDefaultGeometry() .getCoordinateSystem(); if (cs.equals(original)) { throw new IllegalArgumentException("CoordinateSystem " + cs + " already used (check before using wrapper)"); } this.schema = FeatureTypes.transform(type, cs); this.reader = reader; transformer.setMathTransform(CRS.findMathTransform(original, cs, true)); }
/** * sets the highlighted layer * @param highlightLayer - the layer */ public void setHighlightLayer(MapLayer highlightLayer) { this.highlightLayer = highlightLayer; if (this.highlightLayer != null) { geomName = this.highlightLayer.getFeatureSource().getSchema().getDefaultGeometry() .getName(); if ((geomName == null) || (geomName == "")) { geomName = "the_geom"; } } } }
/** * Go back and update the headers with the required info. * * @throws IOException DOCUMENT ME! */ protected void flush() throws IOException { // not sure the check for records <=0 is necessary, // but if records > 0 and shapeType is null there's probably // another problem. if ((records <= 0) && (shapeType == null)) { GeometryAttributeType geometryAttributeType = featureType .getDefaultGeometry(); Class gat = geometryAttributeType.getType(); shapeType = JTSUtilities.getShapeType(gat); } shpWriter.writeHeaders(bounds, shapeType, records, shapefileLength); dbfHeader.setNumRecords(records); dbfChannel.position(0); dbfHeader.writeHeader(dbfChannel); }
/** * Go back and update the headers with the required info. * * @throws IOException * DOCUMENT ME! */ protected void flush() throws IOException { if ((records <= 0) && (shapeType == null)) { GeometryAttributeType geometryAttributeType = featureType .getDefaultGeometry(); Class gat = geometryAttributeType.getType(); shapeType = JTSUtilities.getShapeType(gat); } shpWriter.writeHeaders(bounds, shapeType, records, shapefileLength); dbfHeader.setNumRecords(records); dbfChannel.position(0); dbfHeader.writeHeader(dbfChannel); }
/** * Go back and update the headers with the required info. * * @throws IOException DOCUMENT ME! */ protected void flush() throws IOException { // not sure the check for records <=0 is necessary, // but if records > 0 and shapeType is null there's probably // another problem. if ((records_ <= 0) && (shapeType_ == null)) { final GeometryAttributeType geometryAttributeType = featureType_.getDefaultGeometry(); final Class gat = geometryAttributeType.getType(); shapeType_ = JTSUtilities.getShapeType(gat); } shpWriter_.writeHeaders(bounds_, shapeType_, records_, shapefileLength_); dbfHeader_.setNumRecords(records_); dbfChannel_.position(0); dbfHeader_.writeHeader(dbfChannel_); }
Feature createFeature( FeatureType type, Record record, DbaseFileReader dbfreader, String id ) throws Exception { if (type.getAttributeCount() == 1) { return type.create(new Object[]{getGeom(record.shape(), type.getDefaultGeometry())}, id); } else { DbaseFileHeader header = dbfreader.getHeader(); Object[] all = dbfreader.readEntry(); Object[] values = new Object[type.getAttributeCount()]; for( int i = 0; i < (values.length - 1); i++ ) { values[i] = all[attributeIndexing[i]]; if (header.getFieldName(attributeIndexing[i]).equals(type.getAttributeType(i))) { System.out.println("ok"); } } values[values.length - 1] = getGeom(record.shape(), type.getDefaultGeometry()); return type.create(values, id); } }
originalCs = results.getSchema().getDefaultGeometry().getCoordinateSystem(); else originalCs = this.results.getSchema().getDefaultGeometry().getCoordinateSystem(); this.transform = CRS.findMathTransform(originalCs,destinationCS, true);
/** * Returns the attribute reader, allowing for a pure shapefile reader, or a combined dbf/shp reader. * * @param _readDbf - if true, the dbf fill will be opened and read * @return * @throws IOException */ protected Reader getAttributesReader(boolean _readDbf) throws IOException { AttributeType[] atts = (schema_ == null) ? readAttributes() : schema_.getAttributeTypes(); if (!_readDbf) { LOGGER.fine("The DBF file won't be opened since no attributes will be read from it"); atts = new AttributeType[] { schema_.getDefaultGeometry() }; return new Reader(atts, openShapeReader(), null); } return new Reader(atts, openShapeReader(), openDbfReader()); }
/** * Just like the basic version, but adds a small optimization: if no attributes are going to be read, don't uselessly * open and read the dbf file. * * @see org.geotools.data.AbstractDataStore#getFeatureReader(java.lang.String, org.geotools.data.Query) */ protected FeatureReader getFeatureReader(final String _typeName, final Query _query) throws IOException { final String[] propertyNames = _query.getPropertyNames(); final String defaultGeomName = schema_.getDefaultGeometry().getName(); if ((propertyNames != null) && (propertyNames.length == 1) && propertyNames[0].equals(defaultGeomName)) { try { final FeatureType newSchema = DataUtilities.createSubType(schema_, propertyNames); return createFeatureReader(_typeName, getAttributesReader(false), newSchema); } catch (final SchemaException se) { throw new DataSourceException("Error creating schema", se); } } return super.getFeatureReader(_typeName, _query); }
/** * Returns the attribute reader, allowing for a pure shapefile reader, or a * combined dbf/shp reader. * * @param readDbf - if true, the dbf fill will be opened and read * * * @throws IOException */ protected Reader getAttributesReader(boolean readDbf) throws IOException { AttributeType[] atts = (schema == null) ? readAttributes() : schema.getAttributeTypes(); if (!readDbf) { LOGGER.fine( "The DBF file won't be opened since no attributes will be read from it"); atts = new AttributeType[] { schema.getDefaultGeometry() }; return new Reader(atts, openShapeReader(), null); } return new Reader(atts, openShapeReader(), openDbfReader()); }
/** * Applies transform to all geometry attribute. * * @param feature Feature to be transformed * @param schema Schema for target transformation - transform( schema, crs ) * @param transform MathTransform used to transform coordinates - reproject( crs, crs ) * @return transformed Feature of type schema * @throws TransformException * @throws MismatchedDimensionException * @throws IllegalAttributeException */ public static Feature transform( Feature feature, FeatureType schema, MathTransform transform ) throws MismatchedDimensionException, TransformException, IllegalAttributeException { feature = schema.create(feature.getAttributes(null), feature.getID()); GeometryAttributeType geomType = schema.getDefaultGeometry(); Geometry geom = (Geometry) feature.getAttribute(geomType.getName()); geom = JTS.transform(geom, transform); try { feature.setAttribute(geomType.getName(), geom); } catch (IllegalAttributeException shouldNotHappen) { // we are expecting the transform to return the same geometry type } return feature; }