Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static final class FeaturesAttributeValues {
* projections. However the requester can override this by explicitly declaring that longitude
* axis is first.
*/
@HasDefaultValue public Boolean longitudeFirst = null;
@HasDefaultValue private Boolean longitudeFirst = null;

private SimpleFeatureCollection featuresCollection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public final class GridParam extends AbstractLayerParams {
* projections. However the requester can override this by explicitly declaring that longitude
* axis is first.
*/
@HasDefaultValue public Boolean longitudeFirst = null;
@HasDefaultValue private Boolean longitudeFirst = null;

/**
* If true (the default), the labels will be rotated to follow the lines they belong to. Otherwise
Expand Down Expand Up @@ -266,6 +266,10 @@ public MathTransform calculateLabelTransform(final CoordinateReferenceSystem map
return labelTransform;
}

public CoordinateReferenceSystem getLabelCRS() {
return this.labelCRS;
}

public GridLabelFormat getGridLabelFormat() {
return this.gridLabelFormat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import java.awt.geom.AffineTransform;
import org.geotools.api.feature.simple.SimpleFeatureType;
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.referencing.operation.MathTransform;
import org.geotools.api.referencing.cs.AxisDirection;
import org.geotools.api.referencing.cs.CoordinateSystem;
import org.geotools.api.referencing.operation.TransformException;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.geometry.jts.ReferencedEnvelope;
Expand Down Expand Up @@ -144,8 +145,8 @@ public static void topBorderLabel(
final LabelPositionCollector labels,
final String unit,
final AffineTransform worldToScreenTransform,
final MathTransform toLabelProjection,
final GridLabelFormat labelFormat,
final GridParam layerData,
final CoordinateReferenceSystem mapCrs,
final Geometry intersections) {

if (intersections.getNumPoints() > 0) {
Expand All @@ -154,10 +155,10 @@ public static void topBorderLabel(
worldToScreenTransform.transform(
new double[] {borderIntersection.x, borderIntersection.y}, 0, screenPoints, 0, 1);

double[] labelProj = transformToLabelProjection(toLabelProjection, borderIntersection);
double[] labelProj = transformToLabelProjection(layerData, mapCrs, borderIntersection);
labels.add(
new GridLabel(
createLabel(labelProj[0], unit, labelFormat),
createLabel(labelProj[0], unit, layerData.getGridLabelFormat()),
(int) screenPoints[0],
(int) screenPoints[1],
TOP));
Expand All @@ -176,17 +177,17 @@ public static void bottomBorderLabel(
final LabelPositionCollector labels,
final String unit,
final AffineTransform worldToScreenTransform,
final MathTransform toLabelProjection,
final GridLabelFormat labelFormat,
final GridParam layerData,
final CoordinateReferenceSystem mapCrs,
final Geometry intersections) {

if (intersections.getNumPoints() > 0) {
double[] screenPoints = new double[2];
double[] labelProj =
getLabelProj(worldToScreenTransform, toLabelProjection, intersections, screenPoints);
getLabelProj(worldToScreenTransform, layerData, mapCrs, intersections, screenPoints);
labels.add(
new GridLabel(
createLabel(labelProj[0], unit, labelFormat),
createLabel(labelProj[0], unit, layerData.getGridLabelFormat()),
(int) screenPoints[0],
(int) screenPoints[1],
BOTTOM));
Expand All @@ -206,17 +207,17 @@ public static void rightBorderLabel(
final LabelPositionCollector labels,
final String unit,
final AffineTransform worldToScreenTransform,
final MathTransform toLabelProjection,
final GridLabelFormat labelFormat,
final GridParam layerData,
final CoordinateReferenceSystem mapCrs,
final Geometry intersections) {

if (intersections.getNumPoints() > 0) {
double[] screenPoints = new double[2];
double[] labelProj =
getLabelProj(worldToScreenTransform, toLabelProjection, intersections, screenPoints);
getLabelProj(worldToScreenTransform, layerData, mapCrs, intersections, screenPoints);
labels.add(
new GridLabel(
createLabel(labelProj[1], unit, labelFormat),
createLabel(labelProj[1], unit, layerData.getGridLabelFormat()),
(int) screenPoints[0],
(int) screenPoints[1],
RIGHT));
Expand All @@ -225,15 +226,16 @@ public static void rightBorderLabel(

private static double[] getLabelProj(
final AffineTransform worldToScreenTransform,
final MathTransform toLabelProjection,
final GridParam layerData,
final CoordinateReferenceSystem mapCrs,
final Geometry intersections,
final double[] screenPoints) {
int idx = intersections instanceof LineString ? 1 : 0;
Coordinate borderIntersection = intersections.getGeometryN(0).getCoordinates()[idx];
worldToScreenTransform.transform(
new double[] {borderIntersection.x, borderIntersection.y}, 0, screenPoints, 0, 1);

return transformToLabelProjection(toLabelProjection, borderIntersection);
return transformToLabelProjection(layerData, mapCrs, borderIntersection);
}

/**
Expand All @@ -248,8 +250,8 @@ static void leftBorderLabel(
final LabelPositionCollector labels,
final String unit,
final AffineTransform worldToScreenTransform,
final MathTransform toLabelProjection,
final GridLabelFormat labelFormat,
final GridParam layerData,
final CoordinateReferenceSystem mapCrs,
final Geometry intersections) {

if (intersections.getNumPoints() > 0) {
Expand All @@ -258,23 +260,42 @@ static void leftBorderLabel(
worldToScreenTransform.transform(
new double[] {borderIntersection.x, borderIntersection.y}, 0, screenPoints, 0, 1);

double[] labelProj = transformToLabelProjection(toLabelProjection, borderIntersection);
double[] labelProj = transformToLabelProjection(layerData, mapCrs, borderIntersection);

labels.add(
new GridLabel(
createLabel(labelProj[1], unit, labelFormat),
createLabel(labelProj[1], unit, layerData.getGridLabelFormat()),
(int) screenPoints[0],
(int) screenPoints[1],
LEFT));
}
}

/** Get the horizontal and vertical coordinates on the map. */
private static double[] transformToLabelProjection(
final MathTransform toLabelProjection, final Coordinate borderIntersection) {
final GridParam layerData,
final CoordinateReferenceSystem mapCrs,
final Coordinate borderIntersection) {
try {
double[] labelProj = new double[2];
toLabelProjection.transform(
new double[] {borderIntersection.x, borderIntersection.y}, 0, labelProj, 0, 1);
layerData
.calculateLabelTransform(mapCrs)
.transform(new double[] {borderIntersection.x, borderIntersection.y}, 0, labelProj, 0, 1);

// Get axis directions from the target CRS
CoordinateReferenceSystem labelCrs = layerData.getLabelCRS();
if (labelCrs == null) {
labelCrs = mapCrs;
}
if (labelCrs != null) {
CoordinateSystem cs = labelCrs.getCoordinateSystem();
AxisDirection dir0 = cs.getAxis(0).getDirection();
AxisDirection dir1 = cs.getAxis(1).getDirection();
// If first axis is NORTH or SOUTH, swap axes
if (dir0 == AxisDirection.NORTH || dir0 == AxisDirection.SOUTH) {
return new double[] {labelProj[1], labelProj[0]};
}
}
return labelProj;
} catch (TransformException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,11 @@ private DefaultFeatureCollection sharedCreateFeatures(
Geometry intersectionsTB =
GridUtils.computeTopBorderIntersections(rotatedBounds, geometryFactory, x);
GridUtils.topBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsTB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsTB);
Geometry intersectionsBB =
GridUtils.computeBottomBorderIntersections(rotatedBounds, geometryFactory, x);
GridUtils.bottomBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsBB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsBB);
}

pointSpacing = bounds.getSpan(0) / layerData.pointsInLine;
Expand All @@ -156,21 +146,11 @@ private DefaultFeatureCollection sharedCreateFeatures(
Geometry intersectionsRB =
GridUtils.computeRightBorderIntersections(rotatedBounds, geometryFactory, y);
GridUtils.rightBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsRB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsRB);
Geometry intersectionsLB =
GridUtils.computeLeftBorderIntersections(rotatedBounds, geometryFactory, y);
GridUtils.leftBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsLB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsLB);
}

return features;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,11 @@ private DefaultFeatureCollection createFeaturesFromSpacing(
Geometry intersectionsBB =
GridUtils.computeBottomBorderIntersections(rotatedBounds, geometryFactory, x);
GridUtils.bottomBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsBB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsBB);
Geometry intersectionsTB =
GridUtils.computeTopBorderIntersections(rotatedBounds, geometryFactory, x);
GridUtils.topBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsTB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsTB);
}
for (double y = minY; y < bounds.getMaxY(); y += incrementY) {
j++;
Expand All @@ -100,21 +90,11 @@ private DefaultFeatureCollection createFeaturesFromSpacing(
Geometry intersectionsLB =
GridUtils.computeLeftBorderIntersections(rotatedBounds, geometryFactory, y);
GridUtils.leftBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsLB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsLB);
Geometry intersectionsRB =
GridUtils.computeRightBorderIntersections(rotatedBounds, geometryFactory, y);
GridUtils.rightBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsRB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsRB);
}
if (!onTopBorder(bounds, y)
&& !onBottomBorder(bounds, y)
Expand Down Expand Up @@ -181,42 +161,22 @@ private DefaultFeatureCollection createFeaturesFromNumberOfLines(
Geometry intersectionsLB =
GridUtils.computeLeftBorderIntersections(rotatedBounds, geometryFactory, y);
GridUtils.leftBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsLB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsLB);
} else if (i == layerData.numberOfLines[0] + 1) {
Geometry intersectionsRB =
GridUtils.computeRightBorderIntersections(rotatedBounds, geometryFactory, y);
GridUtils.rightBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsRB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsRB);
} else if (j == 0) {
Geometry intersectionsBB =
GridUtils.computeBottomBorderIntersections(rotatedBounds, geometryFactory, x);
GridUtils.bottomBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsBB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsBB);
} else if (j == layerData.numberOfLines[1] + 1) {
Geometry intersectionsTB =
GridUtils.computeTopBorderIntersections(rotatedBounds, geometryFactory, x);
GridUtils.topBorderLabel(
labels,
unit,
worldToScreenTransform,
labelTransform,
layerData.getGridLabelFormat(),
intersectionsTB);
labels, unit, worldToScreenTransform, layerData, mapCrs, intersectionsTB);
} else {
featureBuilder.reset();
Point geom = geometryFactory.createPoint(new Coordinate(x, y));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"layout": "A4 landscape",
"outputFormat": "png",
"attributes": {
"map": {
"projection": "EPSG:3857",
"dpi": 254,
"rotation": 0,
"center": [-8233518.5005945, 4980320.4059228],
"scale": 250000,
"layers": [
{
"type": "grid",
"gridType": "points",
"numberOfLines": [5, 5],
"renderAsSvg": true,
"labelProjection": "EPSG:4326",
"valueFormat": "###,###.00",
"unitFormat": " %s",
"formatGroupingSeparator": "'",
"font": {
"name": ["Arial", "Helvetica", "Nimbus Sans L", "Liberation Sans", "FreeSans", "Sans-serif"]
}
},
{
"baseURL": "http://geoserver:8080/geoserver/wms",
"opacity": 1,
"type": "WMS",
"layers": ["tiger-ny"],
"imageFormat": "image/png"
}
]
}
}
}
Loading