use of org.opengis.referencing.crs.CoordinateReferenceSystem in project mkgmap by openstreetmap.
the class PrecompSeaGenerator method createTransformation.
/**
* Retrieves the transformation that is necessary to transform the
* data from the shape file to WGS84.
* @param shapeCRS the projection of the shape file
* @return the transformation ({@code null} if no transformation required)
* @throws NoSuchAuthorityCodeException if the given projection of the shape file is not supported
* @throws FactoryException if the given projection of the shape file is not supported
*/
private MathTransform createTransformation(String shapeCRS) throws NoSuchAuthorityCodeException, FactoryException {
if ("WGS84".equals(shapeCRS)) {
return null;
}
if ("Mercator".equals(shapeCRS)) {
shapeCRS = "EPSG:3857";
}
CoordinateReferenceSystem crsInShapefile = CRS.decode(shapeCRS);
CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;
// allow for some error due to different datums
boolean lenient = true;
return CRS.findMathTransform(crsInShapefile, targetCRS, lenient);
}
use of org.opengis.referencing.crs.CoordinateReferenceSystem in project activityinfo by bedatadriven.
the class GeometryConverter method createTransform.
private MathTransform createTransform(GeometryType type) throws FactoryException {
CoordinateReferenceSystem sourceCrs = type.getCoordinateReferenceSystem();
if (sourceCrs == null) {
// if it's not WGS84, we'll soon find out as we check the geometry against the
// country bounds
sourceCrs = DefaultGeographicCRS.WGS84;
}
CoordinateReferenceSystem geoCRS = DefaultGeographicCRS.WGS84;
// allow for some error due to different datums
boolean lenient = true;
return CRS.findMathTransform(sourceCrs, geoCRS, lenient);
}
use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sldeditor by robward-scisys.
the class FieldConfigBoundingBox method getBBox.
/**
* Generates the bounding box from the ui.
*
* @return the b box
*/
private ReferencedEnvelope getBBox() {
if (xMinTextField == null) {
return null;
}
double minX = xMinTextField.getText().isEmpty() ? 0.0 : Double.valueOf(xMinTextField.getText());
double maxX = xMaxTextField.getText().isEmpty() ? 0.0 : Double.valueOf(xMaxTextField.getText());
double minY = yMinTextField.getText().isEmpty() ? 0.0 : Double.valueOf(yMinTextField.getText());
double maxY = yMaxTextField.getText().isEmpty() ? 0.0 : Double.valueOf(yMaxTextField.getText());
ValueComboBoxData crsDataValue = crsComboBox.getSelectedValue();
CoordinateReferenceSystem crs = null;
try {
if (crsDataValue != null) {
crs = CRS.decode(crsDataValue.getKey());
}
} catch (NoSuchAuthorityCodeException e) {
ConsoleManager.getInstance().exception(this, e);
} catch (FactoryException e) {
ConsoleManager.getInstance().exception(this, e);
}
ReferencedEnvelope envelope = new ReferencedEnvelope(minX, maxX, minY, maxY, crs);
return envelope;
}
use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sldeditor by robward-scisys.
the class InLineFeatureModel method updateCRS.
/**
* 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<SimpleFeature>();
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();
}
}
}
use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sldeditor by robward-scisys.
the class CoordManagerTest method testGetInstance.
/**
* Test method for {@link com.sldeditor.common.coordinate.CoordManager#getInstance()}.
* Test method for {@link com.sldeditor.common.coordinate.CoordManager#getCRSList()}.
* Test method for {@link com.sldeditor.common.coordinate.CoordManager#getCRSCode(org.opengis.referencing.crs.CoordinateReferenceSystem)}.
* Test method for {@link com.sldeditor.common.coordinate.CoordManager#getWGS84()}.
*
* @throws NoSuchAuthorityCodeException the no such authority code exception
* @throws FactoryException the factory exception
*/
@Test
public void testGetInstance() throws NoSuchAuthorityCodeException, FactoryException {
CoordManager.getInstance().populateCRSList();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
List<ValueComboBoxData> crsList = CoordManager.getInstance().getCRSList();
assertTrue(crsList.size() > 0);
CoordinateReferenceSystem crs = CoordManager.getInstance().getCRS(null);
assertNull(crs);
crs = CoordManager.getInstance().getWGS84();
assertTrue(crs != null);
String code = CoordManager.getInstance().getCRSCode(null);
assertTrue(code.compareTo("") == 0);
code = CoordManager.getInstance().getCRSCode(crs);
assertTrue(code.compareTo("EPSG:4326") == 0);
String projectedCRSCode = "EPSG:27700";
CoordinateReferenceSystem projectedCRS = CRS.decode(projectedCRSCode);
code = CoordManager.getInstance().getCRSCode(projectedCRS);
assertTrue(code.compareTo(projectedCRSCode) == 0);
}
Aggregations