Search in sources :

Example 21 with FactoryException

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();
        }
    }
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) RevFeatureBuilder(org.locationtech.geogig.api.RevFeatureBuilder) FactoryException(org.opengis.referencing.FactoryException) PropertyType(org.opengis.feature.type.PropertyType) GeometryType(org.opengis.feature.type.GeometryType) RevFeature(org.locationtech.geogig.api.RevFeature) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeogigSimpleFeature(org.locationtech.geogig.api.GeogigSimpleFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevCommit(org.locationtech.geogig.api.RevCommit) Optional(com.google.common.base.Optional) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) ObjectId(org.locationtech.geogig.api.ObjectId) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Geometry(com.vividsolutions.jts.geom.Geometry) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) Collection(java.util.Collection) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevObject(org.locationtech.geogig.api.RevObject) RevTree(org.locationtech.geogig.api.RevTree)

Example 22 with FactoryException

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;
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) FactoryException(org.opengis.referencing.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Point(com.vividsolutions.jts.geom.Point) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 23 with FactoryException

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();
    }
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) Set(java.util.Set) Hints(org.geotools.factory.Hints) FactoryException(org.opengis.referencing.FactoryException) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) Identifier(org.opengis.metadata.Identifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) Collection(java.util.Collection) AuthorityFactory(org.opengis.referencing.AuthorityFactory) Citation(org.opengis.metadata.citation.Citation)

Example 24 with FactoryException

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");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateTransformer(io.georocket.util.CoordinateTransformer) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 25 with FactoryException

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();
    }
}
Also used : Color(java.awt.Color) FactoryException(org.opengis.referencing.FactoryException) XStream(com.thoughtworks.xstream.XStream) Arrays(java.util.Arrays) CRS(org.geotools.referencing.CRS) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) ClickMe(org.twak.tweed.ClickMe) Random(java.util.Random) Mode(com.jme3.scene.Mesh.Mode) PlaneTool(org.twak.tweed.tools.PlaneTool) Vector4f(com.jme3.math.Vector4f) IDumpObjs(org.twak.tweed.IDumpObjs) Material(com.jme3.material.Material) TransformException(org.opengis.referencing.operation.TransformException) Point3d(javax.vecmath.Point3d) VertexBuffer(com.jme3.scene.VertexBuffer) BufferedImage(java.awt.image.BufferedImage) ListDownLayout(org.twak.utils.ui.ListDownLayout) DefaultGeocentricCRS(org.geotools.referencing.crs.DefaultGeocentricCRS) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Dimension(java.awt.Dimension) List(java.util.List) Mesh(com.jme3.scene.Mesh) JPanel(javax.swing.JPanel) Geometry(com.jme3.scene.Geometry) ActionListener(java.awt.event.ActionListener) FacadeTool(org.twak.tweed.tools.FacadeTool) Vector2f(com.jme3.math.Vector2f) Vector3d(javax.vecmath.Vector3d) Filez(org.twak.utils.Filez) Mosaic(org.twak.readTrace.Mosaic) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) Spatial(com.jme3.scene.Spatial) Graphics2D(java.awt.Graphics2D) Mathz(org.twak.utils.Mathz) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) Iterator(java.util.Iterator) Files(java.nio.file.Files) BufferUtils(com.jme3.util.BufferUtils) Vector3f(com.jme3.math.Vector3f) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) MathTransform(org.opengis.referencing.operation.MathTransform) Jme3z(org.twak.siteplan.jme.Jme3z) EventMoveHandle(org.twak.tweed.EventMoveHandle) ObjDump(org.twak.utils.geom.ObjDump) ColorRGBA(com.jme3.math.ColorRGBA) JTextArea(javax.swing.JTextArea) Box(com.jme3.scene.shape.Box) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) MathTransform(org.opengis.referencing.operation.MathTransform) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d)

Aggregations

FactoryException (org.opengis.referencing.FactoryException)32 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)22 TransformException (org.opengis.referencing.operation.TransformException)11 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)8 MathTransform (org.opengis.referencing.operation.MathTransform)8 Collection (java.util.Collection)6 GeometryType (org.opengis.feature.type.GeometryType)5 Geometry (com.vividsolutions.jts.geom.Geometry)4 Hints (org.geotools.factory.Hints)4 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)4 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)4 PropertyType (org.opengis.feature.type.PropertyType)4 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)3 Geometry (org.locationtech.jts.geom.Geometry)3 InternationalString (org.opengis.util.InternationalString)3 Optional (com.google.common.base.Optional)2 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)2