use of org.opengis.referencing.FactoryException in project GeoGig by boundlessgeo.
the class ResponseWriter method writeConflicts.
/**
* Writes the response for a set of conflicts while also supplying the geometry.
*
* @param geogig - a CommandLocator to call commands from
* @param conflicts - a Conflict iterator to build the response from
* @throws XMLStreamException
*/
public void writeConflicts(final Context geogig, Iterator<Conflict> conflicts, final ObjectId ours, final ObjectId theirs) throws XMLStreamException {
Iterator<GeometryConflict> conflictIterator = Iterators.transform(conflicts, new Function<Conflict, GeometryConflict>() {
@Override
public GeometryConflict apply(Conflict input) {
ObjectId commitId = ours;
if (input.getOurs().equals(ObjectId.NULL)) {
commitId = theirs;
}
Optional<RevObject> object = geogig.command(RevObjectParse.class).setObjectId(commitId).call();
RevCommit commit = null;
if (object.isPresent() && object.get() instanceof RevCommit) {
commit = (RevCommit) object.get();
} else {
throw new CommandSpecException("Couldn't resolve id: " + commitId.toString() + " to a commit");
}
object = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call();
Optional<NodeRef> node = Optional.absent();
if (object.isPresent()) {
RevTree tree = (RevTree) object.get();
node = geogig.command(FindTreeChild.class).setParent(tree).setChildPath(input.getPath()).call();
} else {
throw new CommandSpecException("Couldn't resolve commit's treeId");
}
RevFeatureType type = null;
RevFeature feature = null;
if (node.isPresent()) {
object = geogig.command(RevObjectParse.class).setObjectId(node.get().getMetadataId()).call();
if (object.isPresent() && object.get() instanceof RevFeatureType) {
type = (RevFeatureType) object.get();
} else {
throw new CommandSpecException("Couldn't resolve newCommit's featureType");
}
object = geogig.command(RevObjectParse.class).setObjectId(node.get().objectId()).call();
if (object.isPresent() && object.get() instanceof RevFeature) {
feature = (RevFeature) object.get();
} else {
throw new CommandSpecException("Couldn't resolve newCommit's feature");
}
}
GeometryConflict conflict = null;
if (feature != null && type != null) {
String crsCode = null;
Collection<PropertyDescriptor> attribs = type.type().getDescriptors();
for (PropertyDescriptor attrib : attribs) {
PropertyType attrType = attrib.getType();
if (attrType instanceof GeometryType) {
GeometryType gt = (GeometryType) attrType;
CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
if (crs != null) {
try {
crsCode = CRS.lookupIdentifier(Citations.EPSG, crs, false);
} catch (FactoryException e) {
crsCode = null;
}
if (crsCode != null) {
crsCode = "EPSG:" + crsCode;
}
}
break;
}
}
FeatureBuilder builder = new FeatureBuilder(type);
GeogigSimpleFeature simpleFeature = (GeogigSimpleFeature) builder.build(feature.getId().toString(), feature);
Geometry geom = null;
List<Object> attributes = simpleFeature.getAttributes();
for (Object attribute : attributes) {
if (attribute instanceof Geometry) {
geom = (Geometry) attribute;
break;
}
}
conflict = new GeometryConflict(input, geom, crsCode);
}
return conflict;
}
});
while (conflictIterator.hasNext()) {
GeometryConflict next = conflictIterator.next();
if (next != null) {
out.writeStartElement("Feature");
writeElement("change", "CONFLICT");
writeElement("id", next.getConflict().getPath());
writeElement("ourvalue", next.getConflict().getOurs().toString());
writeElement("theirvalue", next.getConflict().getTheirs().toString());
writeElement("geometry", next.getGeometry().toText());
if (next.getCRS() != null) {
writeElement("crs", next.getCRS());
}
out.writeEndElement();
}
}
}
use of org.opengis.referencing.FactoryException in project GeoGig by boundlessgeo.
the class MappingRule method getFeatureType.
/**
* Returns the feature type defined by this rule. This is the feature type that features
* transformed by this rule will have
*
* @return
*/
public SimpleFeatureType getFeatureType() {
if (featureType == null) {
SimpleFeatureTypeBuilder fb = new SimpleFeatureTypeBuilder();
fb.setName(name);
fb.add("id", Long.class);
if (defaultFields != null) {
for (DefaultField df : defaultFields) {
fb.add(df.name().toLowerCase(), df.getFieldClass());
}
}
Set<String> keys = this.fields.keySet();
for (String key : keys) {
AttributeDefinition field = fields.get(key);
Class<?> clazz = field.getType().getBinding();
if (Geometry.class.isAssignableFrom(clazz)) {
Preconditions.checkArgument(geometryType == null, "The mapping has more than one geometry attribute");
CoordinateReferenceSystem epsg4326;
try {
epsg4326 = CRS.decode("EPSG:4326", true);
fb.add(field.getName(), clazz, epsg4326);
} catch (NoSuchAuthorityCodeException e) {
} catch (FactoryException e) {
}
geometryType = clazz;
} else {
fb.add(field.getName(), clazz);
}
}
Preconditions.checkNotNull(geometryType, "The mapping rule does not define a geometry field");
if (!geometryType.equals(Point.class)) {
fb.add("nodes", String.class);
}
featureType = fb.buildFeatureType();
featureBuilder = new SimpleFeatureBuilder(featureType);
}
return featureType;
}
use of org.opengis.referencing.FactoryException in project sldeditor by robward-scisys.
the class CoordManager method populateCRSList.
/**
* Populate crs list.
*/
public void populateCRSList() {
if (isPopulated()) {
Runnable runnable = () -> {
VendorOptionVersion vendorOptionVersion = VendorOptionManager.getInstance().getDefaultVendorOptionVersion();
ValueComboBoxData notSetValue = new ValueComboBoxData(NOT_SET_CRS, Localisation.getString(CoordManager.class, "common.notSet"), vendorOptionVersion);
crsDataList.add(notSetValue);
Hints hints = null;
for (AuthorityFactory factory : ReferencingFactoryFinder.getCRSAuthorityFactories(hints)) {
String authorityCode = NOT_SET_CRS;
Citation citation = factory.getAuthority();
if (citation != null) {
@SuppressWarnings("unchecked") Collection<Identifier> identifierList = (Collection<Identifier>) citation.getIdentifiers();
authorityCode = identifierList.iterator().next().getCode();
}
Set<String> codeList;
try {
codeList = factory.getAuthorityCodes(CoordinateReferenceSystem.class);
for (String code : codeList) {
String fullCode = String.format("%s:%s", authorityCode, code);
String descriptionText = factory.getDescriptionText(code).toString();
String text = String.format("%s - %s", fullCode, descriptionText);
ValueComboBoxData value = new ValueComboBoxData(fullCode, text, vendorOptionVersion);
crsDataList.add(value);
crsMap.put(fullCode, value);
}
} catch (NoSuchAuthorityCodeException e) {
// ConsoleManager.getInstance().exception(this, e);
} catch (FactoryException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
};
Thread thread = new Thread(runnable);
thread.start();
}
}
use of org.opengis.referencing.FactoryException in project georocket by georocket.
the class BoundingBoxIndexerFactory method compileQuery.
@Override
public JsonObject compileQuery(String search) {
CoordinateReferenceSystem crs = null;
String crsCode = null;
String co;
int index = search.lastIndexOf(':');
if (index > 0) {
crsCode = search.substring(0, index);
co = search.substring(index + 1);
} else {
co = search;
}
double[] points = Arrays.stream(co.split(",")).map(String::trim).mapToDouble(Double::parseDouble).toArray();
if (crsCode != null) {
try {
crs = CRS.decode(crsCode);
} catch (FactoryException e) {
throw new RuntimeException(String.format("CRS %s could not be parsed: %s", crsCode, e.getMessage()), e);
}
} else if (defaultCrs != null) {
try {
crs = CoordinateTransformer.decode(defaultCrs);
} catch (FactoryException e) {
throw new RuntimeException(String.format("Default CRS %s could not be parsed: %s", defaultCrs, e.getMessage()), e);
}
}
if (crs != null) {
try {
CoordinateTransformer transformer = new CoordinateTransformer(crs);
points = transformer.transform(points, -1);
} catch (FactoryException e) {
throw new RuntimeException(String.format("CRS %s could not be parsed: %s", crsCode, e.getMessage()), e);
} catch (TransformException e) {
throw new RuntimeException(String.format("Coordinates %s could not be " + "transformed to %s: %s", co, crsCode, e.getMessage()), e);
}
}
double minX = points[0];
double minY = points[1];
double maxX = points[2];
double maxY = points[3];
JsonArray coordinates = new JsonArray();
coordinates.add(new JsonArray().add(minX).add(maxY));
coordinates.add(new JsonArray().add(maxX).add(minY));
return geoShapeQuery("bbox", shape("envelope", coordinates), "intersects");
}
use of org.opengis.referencing.FactoryException in project chordatlas by twak.
the class PanoGen method createPanoGen.
private void createPanoGen(File f, List<Pano> results) {
String name = f.getName().substring(0, f.getName().length() - 4);
try {
String[] sVals = name.split("[_]", 10);
if (sVals.length < 6)
return;
List<Double> pos = Arrays.asList(Arrays.copyOfRange(sVals, 0, 6)).stream().map(z -> Double.parseDouble(z)).collect(Collectors.toList());
double[] trans = new double[] { pos.get(0), pos.get(1), 0 };
double[] north = new double[] { pos.get(0), pos.get(1) + 1e-6, 0 };
// two part transform to align heights - geoid for 4326 is different to 27700
MathTransform latLong2Country = CRS.findMathTransform(CRS.decode(sourceCRS), CRS.decode(TweedSettings.settings.gmlCoordSystem), true);
latLong2Country.transform(trans, 0, trans, 0, 1);
latLong2Country.transform(north, 0, north, 0, 1);
if (TweedSettings.settings.gmlCoordSystem.equals("EPSG:3042")) {
/* madrid?! */
System.out.println("******* dirty hack in place for flipped CS");
double tmp = trans[0];
trans[0] = trans[1];
trans[1] = tmp;
}
MathTransform country2Cartesian = CRS.findMathTransform(CRS.decode(TweedSettings.settings.gmlCoordSystem), DefaultGeocentricCRS.CARTESIAN, true);
country2Cartesian.transform(trans, 0, trans, 0, 1);
country2Cartesian.transform(north, 0, north, 0, 1);
{
Point3d tmp = new Point3d(trans);
TweedSettings.settings.toOrigin.transform(tmp);
tmp.get(trans);
tmp = new Point3d(north);
TweedSettings.settings.toOrigin.transform(tmp);
tmp.get(north);
}
if (TweedSettings.settings.gmlCoordSystem.equals("EPSG:2062")) {
// oviedo :(
trans[2] -= 258;
north[2] -= 258;
trans[0] += 3;
trans[0] += 3;
}
Vector3d location = new Vector3d(trans[0], 2.5f, /* camera height above floor */
trans[2]);
{
Vector3d west = new Vector3d((float) (trans[0] - north[0]), 0f, (float) (north[2] - trans[2]));
west.scale(0.6f / west.length());
location.add(west);
}
System.out.println("pano@ " + location);
results.add(new Pano(name, location, // + 360 - (toNorth * 180 /FastMath.PI ) ) % 360,
(pos.get(3).floatValue() + 180), pos.get(4).floatValue(), pos.get(5).floatValue()));
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
} catch (NoSuchAuthorityCodeException e) {
e.printStackTrace();
} catch (FactoryException e) {
e.printStackTrace();
} catch (TransformException e) {
e.printStackTrace();
}
}
Aggregations