org.geotools.coverage.grid.io,
org.geotools.gce.geotiff,
org.geotools.geometry,
+ org.geotools.geometry.jts,
org.geotools.referencing,
org.opengis.geometry,
org.opengis.referencing,
double y = finalClosestPoint.getY();
double[] midVertexCoords = new double[] { x, y };
- double elevation = 0;
- if (MapsElevationServerPreferences.useElevationServer()) {
- // ok! we use new elevation API to resolve possible elevations for the starting points
- try {
- elevation = SingletonTiffTileInterface.lookup(x, y).doubleValue();
- } catch (Exception ee) {
- LOGGER.error("Could not get elevation from tiff interface", ee);
- }
- }
-
- Resource createdVertex = DistrictNetworkUtil.createVertex(graph, diagram, midVertexCoords, elevation, mapping);
+ Resource createdVertex = DistrictNetworkUtil.createVertex(graph, diagram, midVertexCoords, Double.MAX_VALUE, mapping);
- Optional<Resource> leftEdge = DNEdgeBuilder.create(graph, diagram, currentStartVertexCoords, 0, midVertexCoords, 0, detailedLeftEdgeGeometryCoords, 0.001);
- Optional<Resource> rightEdge = DNEdgeBuilder.create(graph, diagram, midVertexCoords, 0, currentEndVertexCoords, 0, detailedRightEdgeGeometryCoords, 0.001);
-
+ Optional<Resource> leftEdge = DNEdgeBuilder.create(graph, diagram, currentStartVertexCoords, Double.MAX_VALUE, midVertexCoords, Double.MAX_VALUE, detailedLeftEdgeGeometryCoords, 0.001);
+ Optional<Resource> rightEdge = DNEdgeBuilder.create(graph, diagram, midVertexCoords, Double.MAX_VALUE, currentEndVertexCoords, Double.MAX_VALUE, detailedRightEdgeGeometryCoords, 0.001);
}
}
});
double width = result2.getX() * scale - result.getX() * scale;
double height = result2.getY() * scale - result.getY() * scale;
- Rectangle2D translated = new Rectangle2D.Double(x, y, width, Math.abs(height));
+ Rectangle2D translated = new Rectangle2D.Double(x, y - Math.abs(height), width, Math.abs(height));
g2d.draw(translated);
}
double x = ModelledCRS.xToLongitude(pos.getX() / scale);
double y = ModelledCRS.yToLatitude(-pos.getY() / scale);
- double elevation = 0;
- if (MapsElevationServerPreferences.useElevationServer()) {
- // ok! we use new elevation API to resolve possible elevations for the starting points
- try {
- elevation = SingletonTiffTileInterface.lookup(x, y).doubleValue();
- } catch (Exception ee) {
- LOGGER.error("Could not get elevation from tiff interface", ee);
- }
- }
- final double felevation = elevation;
-
boolean leftButton = e.button == MouseEvent.LEFT_BUTTON;
ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> {
if (mapping == null) {
mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping);
}
- DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, felevation, mapping);
+ DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, Double.MAX_VALUE, mapping);
}
});
}, 100, TimeUnit.MILLISECONDS);
detailedGeometryCoords[i++] = lon;
detailedGeometryCoords[i++] = lat;
}
-
- double startElevation = 0;
- double endElevation = 0;
- if (MapsElevationServerPreferences.useElevationServer()) {
- // ok! we use new elevation API to resolve possible elevations for the starting points
- try {
- startElevation = SingletonTiffTileInterface.lookup(startLat, startLon).doubleValue();
- endElevation = SingletonTiffTileInterface.lookup(endLat, endLon).doubleValue();
- } catch (Exception e) {
- LOGGER.error("Could not get elevation from tiff interface", e);
- }
- }
- final double se = startElevation;
- final double ee = endElevation;
+
DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource, diagram);
Simantics.getSession().asyncRequest(new WriteRequest() {
@Override
public void perform(WriteGraph graph) throws DatabaseException {
- builder.create(graph, startCoords, se, endCoords, ee, detailedGeometryCoords, padding);
+ builder.create(graph, startCoords, Double.MAX_VALUE, endCoords, Double.MAX_VALUE, detailedGeometryCoords, padding);
}
});
import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;
import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.layer0.Layer0;
+import org.simantics.maps.elevation.server.SingletonTiffTileInterface;
+import org.simantics.maps.elevation.server.prefs.MapsElevationServerPreferences;
import org.simantics.modeling.ModelingResources;
import org.simantics.modeling.adapters.NewCompositeActionFactory;
import org.simantics.operation.Layer0X;
return edge;
}
+ /**
+ * @param graph
+ * @param composite
+ * @param coords
+ * @param elevation Double.MAX_VALUE to fetch elevation from elevation server (if enabled and has data)
+ * @return
+ * @throws DatabaseException
+ */
public static Resource createVertex(WriteGraph graph, Resource composite, double[] coords, double elevation) throws DatabaseException {
Resource defaultVertexMapping = graph.getPossibleObject(composite, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping);
return createVertex(graph, composite, coords, elevation, defaultVertexMapping);
}
+ /**
+ * @param graph
+ * @param composite
+ * @param coords
+ * @param elevation Double.MAX_VALUE to fetch elevation from elevation server (if enabled and has data)
+ * @param mapping
+ * @return
+ * @throws DatabaseException
+ */
public static Resource createVertex(WriteGraph graph, Resource composite, double[] coords, double elevation, Resource mapping) throws DatabaseException {
+ // Double.MAX_VALUE is our secret to lookup elevation from elevation server
+ if (elevation == Double.MAX_VALUE) {
+ // ok, resolve from server or default to 0
+ if (MapsElevationServerPreferences.useElevationServer()) {
+ // ok! we use new elevation API to resolve possible elevations for the starting points
+ try {
+ elevation = SingletonTiffTileInterface.lookup(coords[1], coords[0]).doubleValue();
+ } catch (Exception ee) {
+ LOGGER.error("Could not get elevation from tiff interface", ee);
+ }
+ } else {
+ elevation = 0;
+ }
+ }
+
Layer0 L0 = Layer0.getInstance(graph);
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
DiagramResource DIA = DiagramResource.getInstance(graph);
package org.simantics.maps.elevation.server;
-import java.awt.geom.Point2D;
import java.awt.image.DataBuffer;
import java.nio.file.Path;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.geometry.Envelope2D;
-import org.geotools.geometry.TransformedDirectPosition;
+import org.geotools.referencing.CRS;
import org.opengis.geometry.DirectPosition;
-import org.opengis.geometry.Envelope;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.operation.TransformException;
+import org.opengis.referencing.operation.MathTransform;
import org.simantics.maps.elevation.server.prefs.MapsElevationServerPreferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final Path tifPath;
private GridCoverage2D coverage;
- private CoordinateReferenceSystem crs;
private boolean init = false;
try {
reader = new GeoTiffReader(this.tifPath.toFile());
this.coverage = reader.read(null);
- this.crs = coverage.getCoordinateReferenceSystem();
this.init = true;
} catch (Exception e) {
LOGGER.error("Could not load {}", tifPath, e);
ensureInit();
Envelope2D e = coverage.getEnvelope2D();
try {
- TransformedDirectPosition tdp = new TransformedDirectPosition(pos.getCoordinateReferenceSystem(), crs, null);
- tdp.transform(pos);
-
- Point2D p = tdp.toPoint2D();
-
- boolean contains = e.contains(p);
+ MathTransform transform = CRS.findMathTransform(pos.getCoordinateReferenceSystem(), getCRS(), false);
+ DirectPosition target = transform.transform(pos, null);
+ boolean contains = e.contains(target);
return contains;
} catch (Exception ex) {
ex.printStackTrace();
}
public CoordinateReferenceSystem getCRS() {
- return crs;
+ return coverage.getCoordinateReferenceSystem();
}
}
import org.geotools.geometry.DirectPosition2D;
import org.geotools.geometry.Envelope2D;
+import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
import org.opengis.geometry.DirectPosition;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.operation.MathTransform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
TiffInterface tifInterface = openTifInterface(tifFile);
Envelope2D coords = tifInterface.getCornerCoords();
try {
- MathTransform transform = CRS.findMathTransform(tifInterface.getCRS(), c4326);
- DirectPosition2D min = new DirectPosition2D();
- DirectPosition2D max = new DirectPosition2D();
- transform.transform(new DirectPosition2D(coords.getMinX(), coords.getMinY()), min);
- transform.transform(new DirectPosition2D(coords.getMaxX(), coords.getMaxY()), max);
- Envelope envelope = new Envelope(min.getX(), max.getX(), min.getY(), max.getY());
+ ReferencedEnvelope refEnv = new ReferencedEnvelope(coords);
+ ReferencedEnvelope targetEnv = refEnv.transform(c4326, false, 30);
+
synchronized(index) {
- index.insert(envelope, tifFile);
+ index.insert(targetEnv, tifFile);
}
- envelopes.put(tifFile, envelope);
+ envelopes.put(tifFile, targetEnv);
} catch (Exception e) {
LOGGER.error("Could not initialize index for file {}", tifFile, e);
} finally {