Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GIS Coordinate Transform to use GeometryInterface #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -33,12 +33,11 @@
import org.cts.registry.EPSGRegistry;
import org.cts.registry.ESRIRegistry;
import org.cts.registry.IGNFRegistry;
import org.cts.registry.RegistryManager;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.row.RowDataUtil;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;

import org.pentaho.di.core.row.value.GeometryInterface;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStep;
Expand All @@ -47,39 +46,27 @@
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;

import com.atolcd.pentaho.di.core.row.value.ValueMetaGeometry;
import com.atolcd.pentaho.di.gis.utils.CoordinateTransformer;
import com.atolcd.pentaho.di.gis.utils.GeometryUtils;
import com.vividsolutions.jts.geom.Geometry;

public class GisCoordinateTransformation extends BaseStep implements StepInterface {

private GisCoordinateTransformationData data;
private GisCoordinateTransformationMeta meta;

Integer geometryFieldIndex;
Integer outputFieldIndex;
String crsOperationType = null;
protected ValueMetaInterface geometryValueMeta;

CRSFactory cRSFactory;
RegistryManager registryManager;

CoordinateOperation transformation = null;

public GisCoordinateTransformation(StepMeta s, StepDataInterface stepDataInterface, int c, TransMeta t, Trans dis) {
super(s, stepDataInterface, c, t, dis);

cRSFactory = new CRSFactory();
registryManager = cRSFactory.getRegistryManager();
registryManager.addRegistry(new IGNFRegistry());
registryManager.addRegistry(new EPSGRegistry());
registryManager.addRegistry(new ESRIRegistry());
public GisCoordinateTransformation(StepMeta stepMeta, StepDataInterface stepData, int c, TransMeta t, Trans dis) {
super(stepMeta, stepData, c, t, dis);
GisCoordinateTransformationData data = ( GisCoordinateTransformationData ) stepData;
GisCoordinateTransformationMeta meta = ( GisCoordinateTransformationMeta ) stepMeta.getStepMetaInterface();
data.cRSFactory = new CRSFactory();
data.registryManager = data.cRSFactory.getRegistryManager();
data.registryManager.addRegistry(new IGNFRegistry());
data.registryManager.addRegistry(new EPSGRegistry());
data.registryManager.addRegistry(new ESRIRegistry());
}

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
meta = (GisCoordinateTransformationMeta) smi;
data = (GisCoordinateTransformationData) sdi;
GisCoordinateTransformationMeta meta = (GisCoordinateTransformationMeta) smi;
GisCoordinateTransformationData data = (GisCoordinateTransformationData) sdi;

Object[] r = getRow();

Expand All @@ -98,7 +85,7 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws K

// Récupération de l'index de la colonne contenant la geométrie
RowMetaInterface inputRowMeta = getInputRowMeta();
geometryFieldIndex = getInputRowMeta().indexOfValue(meta.getGeometryFieldName()); // Récupération
data.geometryFieldIndex = getInputRowMeta().indexOfValue(meta.getGeometryFieldName()); // Récupération
// de
// l'index
// de
Expand All @@ -107,18 +94,18 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws K
// contenant
// la
// geométrie
geometryValueMeta = inputRowMeta.getValueMeta(geometryFieldIndex);

data.geomeryInterface = ( GeometryInterface ) inputRowMeta.getValueMeta( data.geometryFieldIndex );
// Récupération de l'index de la colonne contenant le résultat
outputFieldIndex = data.outputRowMeta.indexOfValue(meta.getOutputGeometryFieldName());
data.outputFieldIndex = data.outputRowMeta.indexOfValue(meta.getOutputGeometryFieldName());

crsOperationType = meta.getCrsOperation();
data.crsOperationType = meta.getCrsOperation();

if (crsOperationType.equalsIgnoreCase("REPROJECT")) {
if (data.crsOperationType.equalsIgnoreCase("REPROJECT")) {

if (!meta.isCrsFromGeometry()) {
transformation = getTransformation(meta.getInputCRSAuthority() + ":" + environmentSubstitute(meta.getInputCRSCode()), meta.getOutputCRSAuthority() + ":"
+ environmentSubstitute(meta.getOutputCRSCode()));
data.transformation = getTransformation(meta.getInputCRSAuthority() + ":" + environmentSubstitute(meta.getInputCRSCode()), meta.getOutputCRSAuthority() + ":"
+ environmentSubstitute(meta.getOutputCRSCode()), data);
}

}
Expand All @@ -128,17 +115,17 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws K
}

Object[] outputRow = RowDataUtil.resizeArray(r, r.length + 1);
Geometry inGeometry = ((ValueMetaGeometry) geometryValueMeta).getGeometry(r[geometryFieldIndex]);
Geometry inGeometry = ( ( GeometryInterface ) data.geomeryInterface ).getGeometry( r[ data.geometryFieldIndex ] );

if (crsOperationType.equalsIgnoreCase("ASSIGN")) {
if (data.crsOperationType.equalsIgnoreCase("ASSIGN")) {

Geometry outGeometry = (Geometry) inGeometry.clone();

if (!GeometryUtils.isNullOrEmptyGeometry(inGeometry)) {
outGeometry.setSRID(Integer.valueOf(environmentSubstitute(meta.getInputCRSCode())));
}

outputRow[outputFieldIndex] = outGeometry;
outputRow[data.outputFieldIndex] = outGeometry;

} else {

Expand All @@ -148,7 +135,7 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws K

if (inGeometry.getSRID() > 0) {

transformation = getTransformation("EPSG:" + inGeometry.getSRID(), meta.getOutputCRSAuthority() + ":" + environmentSubstitute(meta.getOutputCRSCode()));
data.transformation = getTransformation("EPSG:" + inGeometry.getSRID(), meta.getOutputCRSAuthority() + ":" + environmentSubstitute(meta.getOutputCRSCode()), data);

} else {
throw new KettleException("Transformation error : Unknown SRID for geometry " + inGeometry.toString());
Expand All @@ -159,16 +146,16 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws K
}

Geometry outGeometry = null;
if (transformation != null) {
outGeometry = CoordinateTransformer.transform(inGeometry, transformation);
if (data.transformation != null) {
outGeometry = CoordinateTransformer.transform(inGeometry, data.transformation);
}

// Assignation SRID si EPSG
if (meta.getOutputCRSAuthority().equalsIgnoreCase("EPSG") && !GeometryUtils.isNullOrEmptyGeometry(outGeometry)) {
outGeometry.setSRID(Integer.valueOf(environmentSubstitute(meta.getOutputCRSCode())));
}

outputRow[outputFieldIndex] = outGeometry;
outputRow[data.outputFieldIndex] = outGeometry;

}

Expand All @@ -182,58 +169,44 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws K
}

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
meta = (GisCoordinateTransformationMeta) smi;
data = (GisCoordinateTransformationData) sdi;
GisCoordinateTransformationMeta meta = (GisCoordinateTransformationMeta) smi;
GisCoordinateTransformationData data = (GisCoordinateTransformationData) sdi;
return super.init(smi, sdi);
}

public void dispose(StepMetaInterface smi, StepDataInterface sdi) {
meta = (GisCoordinateTransformationMeta) smi;
data = (GisCoordinateTransformationData) sdi;

GisCoordinateTransformationMeta meta = (GisCoordinateTransformationMeta) smi;
GisCoordinateTransformationData data = (GisCoordinateTransformationData) sdi;
super.dispose(smi, sdi);

data.cRSFactory = null;
data.registryManager = null;

}

private CoordinateOperation getTransformation(String inputCRSCode, String outputCRSCode) {
private CoordinateOperation getTransformation(String inputCRSCode, String outputCRSCode, GisCoordinateTransformationData data) throws KettleException {

CoordinateOperation transformation = null;

// Création de la transformation à partir des CRS entrées et sorties
try {

CoordinateReferenceSystem inputCRS = cRSFactory.getCRS(inputCRSCode);
CoordinateReferenceSystem outputCRS = cRSFactory.getCRS(outputCRSCode);
CoordinateReferenceSystem inputCRS = data.cRSFactory.getCRS(inputCRSCode);
CoordinateReferenceSystem outputCRS = data.cRSFactory.getCRS(outputCRSCode);
List<CoordinateOperation> transformations = CoordinateOperationFactory.createCoordinateOperations((GeodeticCRS) inputCRS, (GeodeticCRS) outputCRS);

if (!transformations.isEmpty()) {
transformation = transformations.get(0);
} else {
new KettleException("No transformation available");
throw new KettleException("No transformation available");
}

} catch (CRSException e) {

new KettleException(e);
throw new KettleException(e);
}
return transformation;

}

public void run() {
logBasic("Starting to run...");
try {
while (processRow(meta, data) && !isStopped())
;
} catch (Exception e) {
logError("Unexpected error : " + e.toString());
logError(Const.getStackTracker(e));
setErrors(1);
stopAll();
} finally {
dispose(meta, data);
logBasic("Finished, processing " + getLinesRead() + " rows");
markStop();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,28 @@
* #L%
*/

import org.cts.CRSFactory;
import org.cts.op.CoordinateOperation;
import org.cts.registry.RegistryManager;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.pentaho.di.core.row.value.GeometryInterface;
import org.pentaho.di.trans.step.BaseStepData;
import org.pentaho.di.trans.step.StepDataInterface;

public class GisCoordinateTransformationData extends BaseStepData implements StepDataInterface {

public RowMetaInterface outputRowMeta;
public GeometryInterface geomeryInterface;

Integer geometryFieldIndex;
Integer outputFieldIndex;
String crsOperationType = null;

CRSFactory cRSFactory;
RegistryManager registryManager;

CoordinateOperation transformation = null;

public GisCoordinateTransformationData() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.pentaho.di.core.annotations.Step;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettlePluginException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.pentaho.di.core.row.value.ValueMetaFactory;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.repository.ObjectId;
Expand All @@ -47,6 +49,7 @@
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.metastore.api.IMetaStore;
import org.w3c.dom.Node;

import com.atolcd.pentaho.di.core.row.value.ValueMetaGeometry;
Expand Down Expand Up @@ -147,11 +150,16 @@ public String getXML() {

}

public void getFields(RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) {
public void getFields(RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, IMetaStore metaStore) {

ValueMetaInterface valueMeta = new ValueMetaGeometry(outputGeometryFieldName);
valueMeta.setOrigin(origin);
r.addValueMeta(valueMeta);
ValueMetaInterface valueMeta = null;
try {
valueMeta = ValueMetaFactory.createValueMeta(outputGeometryFieldName, 43663879);
valueMeta.setOrigin(origin);
r.addValueMeta(valueMeta);
} catch (KettlePluginException e) {
e.printStackTrace();
}

}

Expand All @@ -162,7 +170,7 @@ public Object clone() {

}

public void loadXML(Node stepnode, List<DatabaseMeta> databases, Map<String, Counter> counters) throws KettleXMLException {
public void loadXML(Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore) throws KettleXMLException {

try {

Expand All @@ -187,7 +195,9 @@ public void setDefault() {

}

public void check(List<CheckResultInterface> remarks, TransMeta transmeta, StepMeta stepMeta, RowMetaInterface prev, String input[], String output[], RowMetaInterface info) {
public void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ) {

CheckResult cr;

Expand Down Expand Up @@ -217,7 +227,7 @@ public StepDataInterface getStepData() {
return new GisCoordinateTransformationData();
}

public void readRep(Repository rep, ObjectId id_step, List<DatabaseMeta> databases, Map<String, Counter> counters) throws KettleException {
public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException {

try {

Expand All @@ -236,7 +246,7 @@ public void readRep(Repository rep, ObjectId id_step, List<DatabaseMeta> databas
}
}

public void saveRep(Repository rep, ObjectId id_transformation, ObjectId id_step) throws KettleException {
public void saveRep(Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step) throws KettleException {

try {

Expand Down