Skip to content

Commit

Permalink
Revert some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jampukka committed Aug 4, 2023
1 parent fcb9ee2 commit 93dad11
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package fi.nls.oskari.control.feature;

import fi.nls.oskari.domain.map.Feature;
import fi.nls.oskari.log.LogFactory;
import fi.nls.oskari.log.Logger;
import fi.nls.oskari.map.geometry.ProjectionHelper;
import fi.nls.oskari.util.GML3Writer;

import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.Geometry;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.oskari.wfst.WFSTRequestBuilder;

Expand All @@ -15,16 +19,9 @@

public class FeatureWFSTRequestBuilder extends WFSTRequestBuilder {

@Deprecated
/**
* @deprecated see updateFeature(OutputStream, Feature, CoordinateReferenceSystem)
*/
public static void updateFeature(OutputStream out, Feature feature)
throws XMLStreamException {
updateFeature(out, feature, null);
}
private final static Logger LOG = LogFactory.getLogger(FeatureWFSTRequestBuilder.class);

public static void updateFeature(OutputStream out, Feature feature, CoordinateReferenceSystem crs)
public static void updateFeature(OutputStream out, Feature feature)
throws XMLStreamException {
XMLStreamWriter xsw = XOF.createXMLStreamWriter(out);
writeStartTransaction(xsw, "1.1.0");
Expand All @@ -46,7 +43,7 @@ public static void updateFeature(OutputStream out, Feature feature, CoordinateRe
xsw.writeEndElement();
}

writeGeometryProperty(xsw, feature, crs);
writeGeometryProperty(xsw, feature);
writeFeatureIdFilter(xsw, feature.getId());
xsw.writeEndElement(); // close <wfs:Update>

Expand All @@ -55,17 +52,8 @@ public static void updateFeature(OutputStream out, Feature feature, CoordinateRe
xsw.close();
}

@Deprecated
/**
* @deprecated see insertFeature(OutputStream, Feature, CoordinateReferenceSystem)
*/
public static void insertFeature(OutputStream out, Feature feature)
throws XMLStreamException {
insertFeature(out, feature, null);
}

public static void insertFeature(OutputStream out, Feature feature, CoordinateReferenceSystem crs)
throws XMLStreamException {
XMLStreamWriter xsw = XOF.createXMLStreamWriter(out);
writeStartTransaction(xsw, "1.1.0");

Expand All @@ -80,7 +68,7 @@ public static void insertFeature(OutputStream out, Feature feature, CoordinateRe

if (feature.hasGeometry()) {
xsw.writeStartElement(feature.getGMLGeometryProperty());
writeGeometry(xsw, feature.getGeometry(), crs);
writeGeometry(xsw, feature.getGeometry());
xsw.writeEndElement();
}

Expand All @@ -107,7 +95,7 @@ public static void deleteFeature(OutputStream out, Feature feature)
xsw.close();
}

private static void writeGeometryProperty(XMLStreamWriter xsw, Feature feature, CoordinateReferenceSystem crs) throws XMLStreamException {
private static void writeGeometryProperty(XMLStreamWriter xsw, Feature feature) throws XMLStreamException {
if(!feature.hasGeometry()) {
return;
}
Expand All @@ -119,16 +107,23 @@ private static void writeGeometryProperty(XMLStreamWriter xsw, Feature feature,
xsw.writeEndElement();

xsw.writeStartElement(WFS, "Value");
writeGeometry(xsw, feature.getGeometry(), crs);
writeGeometry(xsw, feature.getGeometry());
xsw.writeEndElement();

xsw.writeEndElement();
}

private static void writeGeometry(XMLStreamWriter xsw, Geometry geometry, CoordinateReferenceSystem crs) throws XMLStreamException {
private static void writeGeometry(XMLStreamWriter xsw, Geometry geometry) throws XMLStreamException {
boolean xyOrder = true;
if (crs != null) {
xyOrder = !ProjectionHelper.isFirstAxisNorth(crs);
if (geometry.getSRID() != 0) {
String srsName = GML3Writer.getSrsName(geometry.getSRID());
try {
CoordinateReferenceSystem crs = CRS.decode(srsName);
xyOrder = !ProjectionHelper.isFirstAxisNorth(crs);
LOG.debug("srsName:", srsName, "xyOrder:", xyOrder);
} catch (FactoryException e) {
LOG.warn(e);
}
}
GML3Writer.writeGeometry(xsw, geometry, xyOrder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ public void handlePost(ActionParameters params) throws ActionException {
}

try {
CoordinateReferenceSystem coordRefSys = CRS.decode(crs);

JSONObject geojson = params.getPayLoadJSON();

Feature feature = getFeature(geojson, layerId, crs, geojson.optString("id"));
final String wfstMessage = createWFSTMessageForInsert(feature, coordRefSys);
final String wfstMessage = createWFSTMessageForInsert(feature);
LOG.debug("Inserting feature to service at", layer.getUrl(), "with payload:\n", wfstMessage);
final String responseString = postPayload(layer.getUsername(), layer.getPassword(), wfstMessage, getURLForNamespace(layer.getName(),layer.getUrl()));

Expand Down Expand Up @@ -111,12 +109,10 @@ public void handlePut(ActionParameters params) throws ActionException {
}

try {
CoordinateReferenceSystem coordRefSys = CRS.decode(crs);

JSONObject geojson = params.getPayLoadJSON();
Feature feature = getFeature(geojson, layerId, crs, geojson.optString("id"));

final String wfstMessage = createWFSTMessageForUpdate(feature, coordRefSys);
final String wfstMessage = createWFSTMessageForUpdate(feature);
LOG.debug("Updating feature to service at", layer.getUrl(), "with payload:\n", wfstMessage);
String responseString = postPayload(layer.getUsername(), layer.getPassword(), wfstMessage, getURLForNamespace(layer.getName(),layer.getUrl()));

Expand All @@ -133,22 +129,22 @@ public void handlePut(ActionParameters params) throws ActionException {
}
}

static String createWFSTMessageForUpdate(Feature feature, CoordinateReferenceSystem crs)
static String createWFSTMessageForUpdate(Feature feature)
throws ActionException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FeatureWFSTRequestBuilder.updateFeature(baos, feature, crs);
FeatureWFSTRequestBuilder.updateFeature(baos, feature);
return baos.toString();
} catch (XMLStreamException e) {
throw new ActionException("Failed to create WFS-T request", e);
}
}

static String createWFSTMessageForInsert(Feature feature, CoordinateReferenceSystem coordRefSys)
static String createWFSTMessageForInsert(Feature feature)
throws ActionException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FeatureWFSTRequestBuilder.insertFeature(baos, feature, coordRefSys);
FeatureWFSTRequestBuilder.insertFeature(baos, feature);
return baos.toString();
} catch (XMLStreamException e) {
throw new ActionException("Failed to create WFS-T request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.geotools.referencing.CRS;
import org.junit.Test;
import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Polygon;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

Expand All @@ -27,9 +26,6 @@ public class VectorFeatureWriterHandlerTest {

@Test
public void testUpdateXYAxisOrder() throws Exception {
String epsg = "EPSG:3067";
CoordinateReferenceSystem crs = CRS.decode(epsg);

double[] pts = {
473183.20423224,6680301.618281904,
473257.20423224,6680411.618281904,
Expand All @@ -43,19 +39,18 @@ public void testUpdateXYAxisOrder() throws Exception {
oskariFeature.setId("12345");
oskariFeature.setProperties(new HashMap<>());
oskariFeature.setGMLGeometryProperty("geometry");
oskariFeature.setGeometry(createPolygon(pts));
Geometry g = createPolygon(pts);
g.setSRID(3067);
oskariFeature.setGeometry(g);

String wfsTransaction = VectorFeatureWriterHandler.createWFSTMessageForUpdate(oskariFeature, crs);
String wfsTransaction = VectorFeatureWriterHandler.createWFSTMessageForUpdate(oskariFeature);
double[] actual = readPosList(wfsTransaction);

assertArrayEquals(pts, actual, 1e-10);
}

@Test
public void testInsertYXAxisOrder() throws Exception {
String epsg = "EPSG:3879";
CoordinateReferenceSystem crs = CRS.decode(epsg);

double[] pts = {
25473183.20423224,6680301.618281904,
25473257.20423224,6680411.618281904,
Expand All @@ -68,9 +63,11 @@ public void testInsertYXAxisOrder() throws Exception {
oskariFeature.setLayerName("foo");
oskariFeature.setProperties(new HashMap<>());
oskariFeature.setGMLGeometryProperty("geometry");
oskariFeature.setGeometry(createPolygon(pts));
Geometry g = createPolygon(pts);
g.setSRID(3879);
oskariFeature.setGeometry(g);

String wfsTransaction = VectorFeatureWriterHandler.createWFSTMessageForInsert(oskariFeature, crs);
String wfsTransaction = VectorFeatureWriterHandler.createWFSTMessageForInsert(oskariFeature);
double[] actual = readPosList(wfsTransaction);
for (int i = 0; i < pts.length / 2; i++) {
assertEquals(pts[i * 2 + 0], actual[i * 2 + 1], 1e-10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ private static void writeLinearRing(XMLStreamWriter xsw, LinearRing linearRing,
private static void writeSRID(XMLStreamWriter xsw, int srid)
throws XMLStreamException {
if (srid != 0) {
xsw.writeAttribute("srsName", "http://www.opengis.net/def/crs/EPSG/0/" + srid);
xsw.writeAttribute("srsName", getSrsName(srid));
}
}

public static String getSrsName(int srid) {
return "http://www.opengis.net/def/crs/EPSG/0/" + srid;
}

}

0 comments on commit 93dad11

Please sign in to comment.