Java Code Examples for org.geotools.feature.simple.SimpleFeatureTypeBuilder#retype()

The following examples show how to use org.geotools.feature.simple.SimpleFeatureTypeBuilder#retype() . 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: FeatureDataAdapter.java    From geowave with Apache License 2.0 5 votes vote down vote up
private void initCRS(String indexCrsCode) {
  if ((indexCrsCode == null) || indexCrsCode.isEmpty()) {
    indexCrsCode = GeometryUtils.DEFAULT_CRS_STR;
  }
  CoordinateReferenceSystem persistedCRS = persistedFeatureType.getCoordinateReferenceSystem();

  if (persistedCRS == null) {
    persistedCRS = GeometryUtils.getDefaultCRS();
  }

  final CoordinateReferenceSystem indexCRS = decodeCRS(indexCrsCode);
  if (indexCRS.equals(persistedCRS)) {
    reprojectedFeatureType = SimpleFeatureTypeBuilder.retype(persistedFeatureType, persistedCRS);
    transform = null;
  } else {
    reprojectedFeatureType = SimpleFeatureTypeBuilder.retype(persistedFeatureType, indexCRS);
    try {
      transform = CRS.findMathTransform(persistedCRS, indexCRS, true);
      if (transform.isIdentity()) {
        transform = null;
      }
    } catch (final FactoryException e) {
      LOGGER.warn("Unable to create coordinate reference system transform", e);
    }
  }

  statsManager = new StatsManager(this, persistedFeatureType, reprojectedFeatureType, transform);
}
 
Example 2
Source File: FeatureDataUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static SimpleFeatureType decodeType(
    final String nameSpace,
    final String typeName,
    final String typeDescriptor,
    final String axis) throws SchemaException {

  SimpleFeatureType featureType =
      (nameSpace != null) && (nameSpace.length() > 0)
          ? DataUtilities.createType(nameSpace, typeName, typeDescriptor)
          : DataUtilities.createType(typeName, typeDescriptor);

  final String lCaseAxis = axis.toLowerCase(Locale.ENGLISH);
  final CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem();
  final String typeAxis = getAxis(crs);
  // Default for EPSG:4326 is lat/long, If the provided type was
  // long/lat, then re-establish the order
  if ((crs != null)
      && crs.getIdentifiers().toString().contains("EPSG:4326")
      && !lCaseAxis.equalsIgnoreCase(typeAxis)) {
    final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.init(featureType);

    try {
      // truely no way to force lat first
      // but it is the default in later versions of GeoTools.
      // this all depends on the authority at the time of creation
      featureType =
          SimpleFeatureTypeBuilder.retype(
              featureType,
              CRS.decode("EPSG:4326", lCaseAxis.equals("east")));
    } catch (final FactoryException e) {
      throw new SchemaException("Cannot decode EPSG:4326", e);
    }
  }
  return featureType;
}
 
Example 3
Source File: InLineFeatureModel.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update CRS.
 *
 * @param selectedValue the selected value
 */
public void updateCRS(ValueComboBoxData selectedValue) {
    if (selectedValue != null) {
        String crsCode = selectedValue.getKey();

        CoordinateReferenceSystem newCRS = CoordManager.getInstance().getCRS(crsCode);

        SimpleFeatureType newFeatureType =
                SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), newCRS);

        String typeName = userLayer.getInlineFeatureType().getTypeName();
        try {
            SimpleFeatureSource featureSource =
                    userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);

            SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);

            ArrayList<SimpleFeature> featureList = new ArrayList<>();

            SimpleFeatureIterator it = featureSource.getFeatures().features();
            try {
                while (it.hasNext()) {
                    SimpleFeature sf = it.next();
                    List<Object> attributeValueList = sf.getAttributes();
                    sfb.addAll(attributeValueList);
                    featureList.add(sfb.buildFeature(null));
                }
            } finally {
                it.close();
            }

            SimpleFeatureCollection collection =
                    new ListFeatureCollection(newFeatureType, featureList);

            featureCollection = collection;
            cachedFeature = null;
            lastRow = -1;
            DataStore dataStore = DataUtilities.dataStore(collection);
            userLayer.setInlineFeatureDatastore(dataStore);
            userLayer.setInlineFeatureType(newFeatureType);

        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }

        this.fireTableStructureChanged();
        this.fireTableDataChanged();

        if (parentObj != null) {
            parentObj.inlineFeatureUpdated();
        }
    }
}