Error with CQL, result point is out of the street

4 messages Options
Embed this post
Permalink
Ezequiel Coronel

Error with CQL, result point is out of the street

Reply Threaded More More options
Print post
Permalink
Hi,
    I have a problem when I realize the querys with CQL. The result point is a little bit out of the street.

I put the code that do it the job, the rest of the method are not so important. I' am doing something like this:

         Point point = null;
        StringBuffer query = new StringBuffer();
        query.append("ST_NAME = 'Av. Santa Fe'");
        query.append("and L_REFADDR <=");
        query.append(address.getDoor());
        query.append(" and L_NREFADDR >=");
        query.append(address.getDoor());

        log.info("query "+ query);
        Filter filter = CQL.toFilter(query.toString());

        //get the shape from a folder on the disk
        FeatureSource featureSource = (FeatureSource)featuresSources.get("cap_fed_ejes"); //cap_fed_ejes.shp
        FeatureCollection feactures = featureSource.getFeatures(filter);
       
        CoordinateReferenceSystem targetCRS1 = null;

        try {
            targetCRS1 = CRS.decode("EPSG:4326");//CRS.parseWKT(WGS84);

        } catch (FactoryException e1) {
            e1.printStackTrace();
        }
       
        MathTransform trans1 = null;

        try {
            CoordinateReferenceSystem sourceCRS = targetCRS1;
            log.info("Sistema de coordenadas ordiginal: "+sourceCRS.toString());

            trans1 = CRS.findMathTransform(sourceCRS, targetCRS1);
           
        } catch (NoSuchAuthorityCodeException e) {
            e.printStackTrace();
        } catch (FactoryException e) {
            e.printStackTrace();
        }
      
        FeatureIterator iterator = feactures.features();           
       
        if (feactures.size() != 1) new GeoCodeException("Se encontro más de un valor de geocodificación");
       
        try {
            SimpleFeature feature = (SimpleFeature)iterator.next();
            log.info("Puntos del segmento: ");
            log.info(" inicio impar x " + feature.getAttribute("AII"));
            log.info("; fin impar y " + feature.getAttribute("AFI"));
            log.info("; inicio par x " + feature.getAttribute("AIP"));
            log.info("; fin par y " + feature.getAttribute("AFP"));
        
            log.info("---------------------------------------------------");
            log.info(" getMinX " + feature.getBounds().getMinX());
            log.info("; getMinY " + feature.getBounds().getMinY());
            log.info("; getMaxX " + feature.getBounds().getMaxX());
            log.info("; getMaxY " + feature.getBounds().getMaxY());
            log.info("----------------------------------------------------");
           
            Map points = new Hashtable();
            points.put("x1", String.valueOf(feature.getBounds().getMinX()));
            points.put("y1", String.valueOf(feature.getBounds().getMinY()));
           
            DirectPosition p1 = new GeneralDirectPosition(new Double(feature.getBounds().getMinX()).doubleValue(),new Double(feature.getBounds().getMinY()).doubleValue());
            log.info("------------------------------------------------------------");
            log.info("Punto original p1 : " + p1);

            points.put("x2", String.valueOf(feature.getBounds().getMaxX()));
            points.put("y2", String.valueOf(feature.getBounds().getMaxY()));

            DirectPosition p2 = new GeneralDirectPosition(new Double(feature.getBounds().getMaxX()).doubleValue(),new Double(feature.getBounds().getMaxY()).doubleValue());
            log.info("------------------------------------------------------------");
            log.info("Punto original p2 : " + p2);

            point = UtilInterpolation.interpolate(points, address.getDoor());
            log.info("------------------------------------------------");
           
            log.info("Punto interpolado - x: " + point.getX() + " y: " + point.getY());
           
        } catch (MismatchedDimensionException e) {
            e.printStackTrace();
        }

This is the log.
11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService: ---------------------------------------------------
11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService:  getMinX -58.416011810302734
11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService: ; getMinY -34.585758209228516
11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService: ; getMaxX -58.41497039794922
11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService: ; getMaxY -34.585121154785156
11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService: ----------------------------------------------------
11:04:10.981 INFO  [main] com.ases.geo.services.impl.GeoService: ------------------------------------------------------------
11:04:10.981 INFO  [main] com.ases.geo.services.impl.GeoService: Punto original p1 : GeneralDirectPosition[-58.416011810302734, -34.585758209228516]
11:04:10.981 INFO  [main] com.ases.geo.services.impl.GeoService: ------------------------------------------------------------
11:04:10.981 INFO  [main] com.ases.geo.services.impl.GeoService: Punto original p2 : GeneralDirectPosition[-58.41497039794922, -34.585121154785156]
11:04:10.982 INFO  [main] com.ases.geo.services.impl.GeoService: ------------------------------------------------
11:04:10.982 INFO  [main] com.ases.geo.services.impl.GeoService: Punto interpolado - x: -58.41507453918457 y: -34.58518486022949
11:04:10.982 INFO  [main] com.ases.geo.services.impl.GeoService: Fin del proceso de geo, Duracion: 1s:675ms
11:04:10.982 INFO  [main] com.ases.geo.GeoServiceTest: Y,X = -34.58518486022949,-58.41507453918457

When I search the point Y,X = -34.58518486022949,-58.41507453918457 into google maps, it's a little bit out of the street. To see it please go to http://maps.google.com/ and put this point (just copy like this -34.58518486022949,-58.41507453918457). If you see the arrow, you will see in the middle of the block.

Anybody





       

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Jody Garnett-2

Re: Error with CQL, result point is out of the street

Reply Threaded More More options
Print post
Permalink
So if I understand you are concerned that CQL is losing precision vs  
your original value?


The CQL parser ends up using the JTS WKTReader where reading  
individual coordinates is done by getPreciseCoordinate()

private Coordinate getPreciseCoordinate() throws IOException,  
ParseException {
         Coordinate coord = new Coordinate();
         coord.x = getNextNumber();
         coord.y = getNextNumber();
         if (isNumberNext()) {
             coord.z = getNextNumber();
         }
         precisionModel.makePrecise(coord);
         return coord;
     }

With getNextNumber() boiling down to return Double.parseDouble
(tokenizer.sval);

So some loss is expected when turning a double into text and back  
again; but I don't think that is it....google does not use EPSG:4326  
(they have a different shape for their world). The difference results  
in a slightly different position being represented.

For more info:
- http://docs.codehaus.org/display/GEOTDOC/08+Google+Maps+Projection

Jody


On 18/09/2009, at 12:34 AM, Ezequiel Coronel wrote:

> Hi,
>     I have a problem when I realize the querys with CQL. The result  
> point is a little bit out of the street.
>
> I put the code that do it the job, the rest of the method are not so  
> important. I' am doing something like this:
>
>          Point point = null;
>         StringBuffer query = new StringBuffer();
>         query.append("ST_NAME = 'Av. Santa Fe'");
>         query.append("and L_REFADDR <=");
>         query.append(address.getDoor());
>         query.append(" and L_NREFADDR >=");
>         query.append(address.getDoor());
>
>         log.info("query "+ query);
>         Filter filter = CQL.toFilter(query.toString());
>
>         //get the shape from a folder on the disk
>         FeatureSource featureSource = (FeatureSource)
> featuresSources.get("cap_fed_ejes"); //cap_fed_ejes.shp
>         FeatureCollection feactures = featureSource.getFeatures
> (filter);
>
>         CoordinateReferenceSystem targetCRS1 = null;
>
>         try {
>             targetCRS1 = CRS.decode("EPSG:4326");//CRS.parseWKT
> (WGS84);
>
>         } catch (FactoryException e1) {
>             e1.printStackTrace();
>         }
>
>         MathTransform trans1 = null;
>
>         try {
>             CoordinateReferenceSystem sourceCRS = targetCRS1;
>             log.info("Sistema de coordenadas ordiginal:  
> "+sourceCRS.toString());
>
>             trans1 = CRS.findMathTransform(sourceCRS, targetCRS1);
>
>         } catch (NoSuchAuthorityCodeException e) {
>             e.printStackTrace();
>         } catch (FactoryException e) {
>             e.printStackTrace();
>         }
>
>         FeatureIterator iterator = feactures.features();
>
>         if (feactures.size() != 1) new GeoCodeException("Se encontro  
> más de un valor de geocodificación");
>
>         try {
>             SimpleFeature feature = (SimpleFeature)iterator.next();
>             log.info("Puntos del segmento: ");
>             log.info(" inicio impar x " + feature.getAttribute
> ("AII"));
>             log.info("; fin impar y " + feature.getAttribute("AFI"));
>             log.info("; inicio par x " + feature.getAttribute("AIP"));
>             log.info("; fin par y " + feature.getAttribute("AFP"));
>
>             log.info
> ("---------------------------------------------------");
>             log.info(" getMinX " + feature.getBounds().getMinX());
>             log.info("; getMinY " + feature.getBounds().getMinY());
>             log.info("; getMaxX " + feature.getBounds().getMaxX());
>             log.info("; getMaxY " + feature.getBounds().getMaxY());
>             log.info
> ("----------------------------------------------------");
>
>             Map points = new Hashtable();
>             points.put("x1", String.valueOf(feature.getBounds
> ().getMinX()));
>             points.put("y1", String.valueOf(feature.getBounds
> ().getMinY()));
>
>             DirectPosition p1 = new GeneralDirectPosition(new Double
> (feature.getBounds().getMinX()).doubleValue(),new Double
> (feature.getBounds().getMinY()).doubleValue());
>             log.info
> ("------------------------------------------------------------");
>             log.info("Punto original p1 : " + p1);
>
>             points.put("x2", String.valueOf(feature.getBounds
> ().getMaxX()));
>             points.put("y2", String.valueOf(feature.getBounds
> ().getMaxY()));
>
>             DirectPosition p2 = new GeneralDirectPosition(new Double
> (feature.getBounds().getMaxX()).doubleValue(),new Double
> (feature.getBounds().getMaxY()).doubleValue());
>             log.info
> ("------------------------------------------------------------");
>             log.info("Punto original p2 : " + p2);
>
>             point = UtilInterpolation.interpolate(points,  
> address.getDoor());
>             log.info
> ("------------------------------------------------");
>
>             log.info("Punto interpolado - x: " + point.getX() + " y:  
> " + point.getY());
>
>         } catch (MismatchedDimensionException e) {
>             e.printStackTrace();
>         }
>
> This is the log.
> 11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService:  
> ---------------------------------------------------
> 11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService:  
> getMinX -58.416011810302734
> 11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService: ;  
> getMinY -34.585758209228516
> 11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService: ;  
> getMaxX -58.41497039794922
> 11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService: ;  
> getMaxY -34.585121154785156
> 11:04:10.980 INFO  [main] com.ases.geo.services.impl.GeoService:  
> ----------------------------------------------------
> 11:04:10.981 INFO  [main] com.ases.geo.services.impl.GeoService:  
> ------------------------------------------------------------
> 11:04:10.981 INFO  [main] com.ases.geo.services.impl.GeoService:  
> Punto original p1 : GeneralDirectPosition[-58.416011810302734,  
> -34.585758209228516]
> 11:04:10.981 INFO  [main] com.ases.geo.services.impl.GeoService:  
> ------------------------------------------------------------
> 11:04:10.981 INFO  [main] com.ases.geo.services.impl.GeoService:  
> Punto original p2 : GeneralDirectPosition[-58.41497039794922,  
> -34.585121154785156]
> 11:04:10.982 INFO  [main] com.ases.geo.services.impl.GeoService:  
> ------------------------------------------------
> 11:04:10.982 INFO  [main] com.ases.geo.services.impl.GeoService:  
> Punto interpolado - x: -58.41507453918457 y: -34.58518486022949
> 11:04:10.982 INFO  [main] com.ases.geo.services.impl.GeoService: Fin  
> del proceso de geo, Duracion: 1s:675ms
> 11:04:10.982 INFO  [main] com.ases.geo.GeoServiceTest: Y,X =  
> -34.58518486022949,-58.41507453918457
>
> When I search the point Y,X = -34.58518486022949,-58.41507453918457  
> into google maps, it's a little bit out of the street. To see it  
> please go to http://maps.google.com/ and put this point (just copy  
> like this -34.58518486022949,-58.41507453918457). If you see the  
> arrow, you will see in the middle of the block.
>
> Anybody
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart  
> your
> developing skills, take BlackBerry mobile applications to market and  
> stay
> ahead of the curve. Join us from November 9-12, 2009. Register  
> now!
> http://p.sf.net/sfu/devconf_______________________________________________
> Geotools-gt2-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Mauricio Pazos

Re: Error with CQL, result point is out of the street

Reply Threaded More More options
Print post
Permalink
In reply to this post by Ezequiel Coronel
On Thursday 17 September 2009 04:34:34 pm Ezequiel Coronel wrote:

> Hi,
>     I have a problem when I realize the querys with CQL. The result point
> is a little bit out of the street.
>
> I put the code that do it the job, the rest of the method are not so
> important. I' am doing something like this:
>
>          Point point = null;
>         StringBuffer query = new StringBuffer();
>         query.append("ST_NAME = 'Av. Santa Fe'");
>         query.append("and L_REFADDR <=");
>         query.append(address.getDoor());
>         query.append(" and L_NREFADDR >=");
>         query.append(address.getDoor());
>
>         log.info("query "+ query);
>         Filter filter = CQL.toFilter(query.toString());
>
>         //get the shape from a folder on the disk
>         FeatureSource featureSource =
> (FeatureSource)featuresSources.get("cap_fed_ejes"); //cap_fed_ejes.shp
>         FeatureCollection feactures = featureSource.getFeatures(filter);
>
>         CoordinateReferenceSystem targetCRS1 = null;
>
>         try {
>             targetCRS1 = CRS.decode("EPSG:4326");//CRS.parseWKT(WGS84);
>
>         } catch (FactoryException e1) {
>             e1.printStackTrace();
>         }
>
>         MathTransform trans1 = null;
>
>         try {
>             CoordinateReferenceSystem sourceCRS = targetCRS1;
Are you sure that source and target CRSs are equal?

>             log.info("Sistema de coordenadas ordiginal:
> "+sourceCRS.toString());
>
>             trans1 = CRS.findMathTransform(sourceCRS, targetCRS1);
>
>         } catch (NoSuchAuthorityCodeException e) {
>             e.printStackTrace();
>         } catch (FactoryException e) {
>             e.printStackTrace();
>         }
If the CRSs are not equal, you should reproject the points. Have a look at
GeometryCoordinateSequenceTransformer that is responsible of transforming the
geom.

cheers
--
Mauricio Pazos
www.axios.es

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Ezequiel Coronel

Re: Error with CQL, result point is out of the street

Reply Threaded More More options
Print post
Permalink
HI, thanks to all ...... finally I resolved this problem but not in a good way (I think), I transform the result point to another pair of axis that I calculate. I suppose that there is a function to do this, but for now I'll will do it like this because I don't have time to search any more.

Thanks again!!
Ezequiel.

2009/9/21 Mauricio Pazos <[hidden email]>
On Thursday 17 September 2009 04:34:34 pm Ezequiel Coronel wrote:
> Hi,
>     I have a problem when I realize the querys with CQL. The result point
> is a little bit out of the street.
>
> I put the code that do it the job, the rest of the method are not so
> important. I' am doing something like this:
>
>          Point point = null;
>         StringBuffer query = new StringBuffer();
>         query.append("ST_NAME = 'Av. Santa Fe'");
>         query.append("and L_REFADDR <=");
>         query.append(address.getDoor());
>         query.append(" and L_NREFADDR >=");
>         query.append(address.getDoor());
>
>         log.info("query "+ query);
>         Filter filter = CQL.toFilter(query.toString());
>
>         //get the shape from a folder on the disk
>         FeatureSource featureSource =
> (FeatureSource)featuresSources.get("cap_fed_ejes"); //cap_fed_ejes.shp
>         FeatureCollection feactures = featureSource.getFeatures(filter);
>
>         CoordinateReferenceSystem targetCRS1 = null;
>
>         try {
>             targetCRS1 = CRS.decode("EPSG:4326");//CRS.parseWKT(WGS84);
>
>         } catch (FactoryException e1) {
>             e1.printStackTrace();
>         }
>
>         MathTransform trans1 = null;
>
>         try {
>             CoordinateReferenceSystem sourceCRS = targetCRS1;
Are you sure that source and target CRSs are equal?

>             log.info("Sistema de coordenadas ordiginal:
> "+sourceCRS.toString());
>
>             trans1 = CRS.findMathTransform(sourceCRS, targetCRS1);
>
>         } catch (NoSuchAuthorityCodeException e) {
>             e.printStackTrace();
>         } catch (FactoryException e) {
>             e.printStackTrace();
>         }
If the CRSs are not equal, you should reproject the points. Have a look at
GeometryCoordinateSequenceTransformer that is responsible of transforming the
geom.

cheers
--
Mauricio Pazos
www.axios.es


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users