Dear dev team,

Shall I open an issue in the issue tracker for this? Or is it a user misunderstanding that I am expecting the referencing module to handle transformation from 2D to 3D CRS by simply adding doing a 2D transformation and adding a zero value for Z-axis value?

On 02/14/2011 10:52 AM, Farrukh Najmi wrote:

Hi Javier,

Thanks for sharing your transformation code. It seems to be transforming JTS Coordinate whereas I am looking to transform JTS Geometry.

Here is the code I am using based on the gt-referencing module's JTS.transform() method...

                Geomtry sourceGeometry = ...
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326"); CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4979");

MathTransform transform = CRS.findMathTransform(sourceCRS, internalCRS, true); Geometry targetGeometry = JTS.transform( sourceGeometry, transform);
                targetGeometry.setSRID(4979);

I would like to find a solution that is leveraging gt-referencing module's JTS.transform() method as much as possible.

Thanks for any suggestions.


On 02/14/2011 10:21 AM, Javier Moreno wrote:
I'm not using postgresql epsg but maybe the code I use to reproject will be useful to you. Just in case:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.ub.bio.wms;

import com.vividsolutions.jts.geom.Coordinate;
import edu.ub.bio.framework.SystemException;
import edu.ub.bio.wms.datasources.DBConnectionFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;

/**
 *
 * @author ciberado
 */
public class CoordinateTransformationService {

    private CoordinateReferenceSystem sourceCRS;
    private CoordinateReferenceSystem targetCRS;

    public CoordinateTransformationService() {
        try {
            sourceCRS = CRS.decode("EPSG:27573");
            targetCRS = CRS.decode("EPSG:4326");
        } catch (NoSuchAuthorityCodeException ex) {
            throw new SystemException(ex);
        } catch (FactoryException ex) {
            throw new SystemException(ex);
        }
    }

    private Coordinate transform(double x, double y) {
        try {
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
            Coordinate source = new Coordinate(x, y);
            Coordinate destination = new Coordinate();
            JTS.transform(source, destination, transform);
            return destination;
        } catch (TransformException ex) {
            throw new SystemException(ex);
        } catch (FactoryException ex) {
            throw new SystemException(ex);
        }
    }


    public static void main(String[] args) {
        CoordinateTransformationService cts =
                new CoordinateTransformationService();
        System.out.println(cts.transform("3 526 32"));
    }
}


On Mon, Feb 14, 2011 at 4:14 PM, Farrukh Najmi <farr...@wellfleetsoftware.com <mailto:farr...@wellfleetsoftware.com>> wrote:


    I am using a PostGres/PostGIS 8.3 database with gt-epsg-postgresql
    plugin. The EPSG Geodetic Parameter Dataset has been loaded into
    postgres from EPSG version 7.6.

    When I try to transform a geometry from EPSG:4326 (2D CRS) to
    EPSG:4979
    (3D CRS) I get the following:

    Caused by:
    org.opengis.referencing.operation.OperationNotFoundException:
    No transformation available from system "EllipsoidalCS[Ellipsoidal 2D
    CS. Axes: latitude, longitude. Orientations: north, east. UoM:
    degree]"
    to "EllipsoidalCS[Ellipsoidal 3D CS. Axes: latitude, longitude,
    ellipsoidal height. Orientations: north, east, up. UoM: degree,
    degree,
    metre.]".
            at
    
org.geotools.referencing.operation.AbstractCoordinateOperationFactory.swapAndScaleAxis(AbstractCoordinateOperationFactory.java:278)
            at
    
org.geotools.referencing.operation.DefaultCoordinateOperationFactory.swapAndScaleAxis(DefaultCoordinateOperationFactory.java:591)
            at
    
org.geotools.referencing.operation.DefaultCoordinateOperationFactory.createOperationStep(DefaultCoordinateOperationFactory.java:780)
            at
    
org.geotools.referencing.operation.DefaultCoordinateOperationFactory.createOperation(DefaultCoordinateOperationFactory.java:239)
            at
    
org.geotools.referencing.operation.BufferedCoordinateOperationFactory.createOperation(BufferedCoordinateOperationFactory.java:254)
            at
    org.geotools.referencing.CRS.findMathTransform(CRS.java:1097)
            ... 50 more
    Caused by: java.lang.IllegalArgumentException: No source axis
    match UP.
            at
    
org.geotools.referencing.operation.matrix.GeneralMatrix.<init>(GeneralMatrix.java:314)
            at
    
org.geotools.referencing.operation.matrix.GeneralMatrix.<init>(GeneralMatrix.java:221)
            at
    org.geotools.referencing.cs.AbstractCS.swapAndScaleAxis(AbstractCS.java:331)
            at
    
org.geotools.referencing.operation.AbstractCoordinateOperationFactory.swapAndScaleAxis(AbstractCoordinateOperationFactory.java:276)

    It seems to me that 2D to 3D transform should be simple (just add a 0
    value for Z axis). Is there a way to do this? If not, shall I file an
    RFE? Thanks for your help.



--
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to