Incorrect projection of a shapefile and a geotiff file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Incorrect projection of a shapefile and a geotiff file

Ahmed Eldawy
Hi all,

I am new to GeoTools. I was trying to load a file that represents all US states downloaded from here.
and the following GeoTIFF file

I also use the ImageLab example from GeoTools website to load the two files.

I use getools 17.0

What happens is that the shapefile is rotated 90 degrees. The same files are loaded correctly in QGIS. It happens with other files as well that are also loaded correctly in QGIS.

When I investigate the problem closely, I found that both files are loaded correctly. However, when the Shapefile is projected to the CoordinateReferenceSystem of the GeoTIFF file, the latitudes and longitudes are exchanged. This results in incorrect results when they are combined. Can you provide any help in why this problem happens and how I can solve it?

Best regards,
Ahmed Eldawy


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect projection of a shapefile and a geotiff file

geowolf
The shapefile in question does not define an axis order:

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]

As a result, GeoTools picks the order of international standards, which is lat/lon. However, shapefiles are normally encoded lon/lat...
Add this at the beginning of the file to force a "east/north" order:

System.setProperty("org.geotools.referencing.forceXY", "true");

The shapefile reader internal code should probably be forcing this order by default... although
care should be taken for those prj that do define an axis order. Needs some research, not a 5 minutes change.

Cheers
Andrea


On Tue, Jun 6, 2017 at 7:53 PM, Ahmed Eldawy <[hidden email]> wrote:
Hi all,

I am new to GeoTools. I was trying to load a file that represents all US states downloaded from here.
and the following GeoTIFF file

I also use the ImageLab example from GeoTools website to load the two files.

I use getools 17.0

What happens is that the shapefile is rotated 90 degrees. The same files are loaded correctly in QGIS. It happens with other files as well that are also loaded correctly in QGIS.

When I investigate the problem closely, I found that both files are loaded correctly. However, when the Shapefile is projected to the CoordinateReferenceSystem of the GeoTIFF file, the latitudes and longitudes are exchanged. This results in incorrect results when they are combined. Can you provide any help in why this problem happens and how I can solve it?

Best regards,
Ahmed Eldawy


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054  Massarosa (LU)
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect projection of a shapefile and a geotiff file

Ahmed Eldawy
I tried the shapefile that you sent. Indeed it loads incorrectly in QGIS. In my program, it only gives me the correct results if I use the property line that you sent earlier
System.setProperty("org.geotools.referencing.forceXY", "true");
Without that line, it gives me incorrect results. In other words, when I set forceXY to true, the generated MathTransformation exchanges lat/lon into lon/lat so that it works correctly when I process it with the GeoTIFF file. If forceXY is not set to true, the generate MathTransformation is just the identity transformation and it leaves the order of the axis as lat/lon which does not match the raster file.
This is good news for me because it means that I can keep forceXY to true. However, I'm not sure that I completely understand what is going on.
I think it has something to do with the raster file being processed. When I try the clouds.jpg dataset available at the following link
It works with both shapefiles correctly with or without setting forceXY to true.

Thanks
Ahmed

On Tue, Jun 6, 2017 at 10:51 PM, Andrea Aime <[hidden email]> wrote:
Hi Ahmed,
I don't know what would happen, if you are interested you can try with a shapefile produced
by a WFS 1.1 server (which by spec should default to lat/lon order, even if the spec is not clear
about what to do with shapefiles).
For example, this is in lat/lon order:


QGIS for example ignores its explicit axis order and display it flipped, not sure what GeoTools will do.

Cheers
Andrea


On Wed, Jun 7, 2017 at 12:19 AM, Ahmed Eldawy <[hidden email]> wrote:
Thanks Andrea. I added that line and it fixed the problem. Is this going to break if a file uses YX ordering? It could be better to change the default to XY if it is not specified in the file, as in my case, but use the ordering specified in the file if it presents.

On Tue, Jun 6, 2017 at 11:07 AM, Andrea Aime <[hidden email]> wrote:
The shapefile in question does not define an axis order:

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]

As a result, GeoTools picks the order of international standards, which is lat/lon. However, shapefiles are normally encoded lon/lat...
Add this at the beginning of the file to force a "east/north" order:

System.setProperty("org.geotools.referencing.forceXY", "true");

The shapefile reader internal code should probably be forcing this order by default... although
care should be taken for those prj that do define an axis order. Needs some research, not a 5 minutes change.

Cheers
Andrea


On Tue, Jun 6, 2017 at 7:53 PM, Ahmed Eldawy <[hidden email]> wrote:
Hi all,

I am new to GeoTools. I was trying to load a file that represents all US states downloaded from here.
and the following GeoTIFF file

I also use the ImageLab example from GeoTools website to load the two files.

I use getools 17.0

What happens is that the shapefile is rotated 90 degrees. The same files are loaded correctly in QGIS. It happens with other files as well that are also loaded correctly in QGIS.

When I investigate the problem closely, I found that both files are loaded correctly. However, when the Shapefile is projected to the CoordinateReferenceSystem of the GeoTIFF file, the latitudes and longitudes are exchanged. This results in incorrect results when they are combined. Can you provide any help in why this problem happens and how I can solve it?

Best regards,
Ahmed Eldawy


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054  Massarosa (LU)
phone: <a href="tel:+39%200584%20962313" value="+390584962313" target="_blank">+39 0584 962313
fax: <a href="tel:+39%200584%20166%200272" value="+3905841660272" target="_blank">+39 0584 1660272
mob: <a href="tel:+39%20339%20884%204549" value="+393398844549" target="_blank">+39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------




--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054  Massarosa (LU)
phone: <a href="tel:+39%200584%20962313" value="+390584962313" target="_blank">+39 0584 962313
fax: <a href="tel:+39%200584%20166%200272" value="+3905841660272" target="_blank">+39 0584 1660272
mob: <a href="tel:+39%20339%20884%204549" value="+393398844549" target="_blank">+39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect projection of a shapefile and a geotiff file

Ian Turton
Actually you can use the following (cribbed from the ImageTutorial)  as the issue is with the GeoTiff reader, which is why your JPG works.

        AbstractGridFormat format = GridFormatFinder.findFormat( rasterFile ); 
        //this is a bit hacky but does make more geotiffs work
        Hints hints = new Hints();
        if (format instanceof GeoTiffFormat) {
            hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
        }
        reader = format.getReader(rasterFile, hints);
Ian

On 8 June 2017 at 20:08, Ahmed Eldawy <[hidden email]> wrote:
I tried the shapefile that you sent. Indeed it loads incorrectly in QGIS. In my program, it only gives me the correct results if I use the property line that you sent earlier
System.setProperty("org.geotools.referencing.forceXY", "true");
Without that line, it gives me incorrect results. In other words, when I set forceXY to true, the generated MathTransformation exchanges lat/lon into lon/lat so that it works correctly when I process it with the GeoTIFF file. If forceXY is not set to true, the generate MathTransformation is just the identity transformation and it leaves the order of the axis as lat/lon which does not match the raster file.
This is good news for me because it means that I can keep forceXY to true. However, I'm not sure that I completely understand what is going on.
I think it has something to do with the raster file being processed. When I try the clouds.jpg dataset available at the following link
It works with both shapefiles correctly with or without setting forceXY to true.

Thanks
Ahmed

On Tue, Jun 6, 2017 at 10:51 PM, Andrea Aime <[hidden email]> wrote:
Hi Ahmed,
I don't know what would happen, if you are interested you can try with a shapefile produced
by a WFS 1.1 server (which by spec should default to lat/lon order, even if the spec is not clear
about what to do with shapefiles).
For example, this is in lat/lon order:


QGIS for example ignores its explicit axis order and display it flipped, not sure what GeoTools will do.

Cheers
Andrea


On Wed, Jun 7, 2017 at 12:19 AM, Ahmed Eldawy <[hidden email]> wrote:
Thanks Andrea. I added that line and it fixed the problem. Is this going to break if a file uses YX ordering? It could be better to change the default to XY if it is not specified in the file, as in my case, but use the ordering specified in the file if it presents.

On Tue, Jun 6, 2017 at 11:07 AM, Andrea Aime <[hidden email]> wrote:
The shapefile in question does not define an axis order:

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]

As a result, GeoTools picks the order of international standards, which is lat/lon. However, shapefiles are normally encoded lon/lat...
Add this at the beginning of the file to force a "east/north" order:

System.setProperty("org.geotools.referencing.forceXY", "true");

The shapefile reader internal code should probably be forcing this order by default... although
care should be taken for those prj that do define an axis order. Needs some research, not a 5 minutes change.

Cheers
Andrea


On Tue, Jun 6, 2017 at 7:53 PM, Ahmed Eldawy <[hidden email]> wrote:
Hi all,

I am new to GeoTools. I was trying to load a file that represents all US states downloaded from here.
and the following GeoTIFF file

I also use the ImageLab example from GeoTools website to load the two files.

I use getools 17.0

What happens is that the shapefile is rotated 90 degrees. The same files are loaded correctly in QGIS. It happens with other files as well that are also loaded correctly in QGIS.

When I investigate the problem closely, I found that both files are loaded correctly. However, when the Shapefile is projected to the CoordinateReferenceSystem of the GeoTIFF file, the latitudes and longitudes are exchanged. This results in incorrect results when they are combined. Can you provide any help in why this problem happens and how I can solve it?

Best regards,
Ahmed Eldawy


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054  Massarosa (LU)
phone: <a href="tel:+39%200584%20962313" value="+390584962313" target="_blank">+39 0584 962313
fax: <a href="tel:+39%200584%20166%200272" value="+3905841660272" target="_blank">+39 0584 1660272
mob: <a href="tel:+39%20339%20884%204549" value="+393398844549" target="_blank">+39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------




--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054  Massarosa (LU)
phone: <a href="tel:+39%200584%20962313" value="+390584962313" target="_blank">+39 0584 962313
fax: <a href="tel:+39%200584%20166%200272" value="+3905841660272" target="_blank">+39 0584 1660272
mob: <a href="tel:+39%20339%20884%204549" value="+393398844549" target="_blank">+39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
Ian Turton

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect projection of a shapefile and a geotiff file

Ahmed Eldawy
Hi Ian,

Thanks for the update. The line that you sent also worked fine. I like this solution more as it limits the fix to GeoTiff files.

On Fri, Jun 9, 2017 at 1:53 AM, Ian Turton <[hidden email]> wrote:
Actually you can use the following (cribbed from the ImageTutorial)  as the issue is with the GeoTiff reader, which is why your JPG works.

        AbstractGridFormat format = GridFormatFinder.findFormat( rasterFile ); 
        //this is a bit hacky but does make more geotiffs work
        Hints hints = new Hints();
        if (format instanceof GeoTiffFormat) {
            hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
        }
        reader = format.getReader(rasterFile, hints);
Ian

On 8 June 2017 at 20:08, Ahmed Eldawy <[hidden email]> wrote:
I tried the shapefile that you sent. Indeed it loads incorrectly in QGIS. In my program, it only gives me the correct results if I use the property line that you sent earlier
System.setProperty("org.geotools.referencing.forceXY", "true");
Without that line, it gives me incorrect results. In other words, when I set forceXY to true, the generated MathTransformation exchanges lat/lon into lon/lat so that it works correctly when I process it with the GeoTIFF file. If forceXY is not set to true, the generate MathTransformation is just the identity transformation and it leaves the order of the axis as lat/lon which does not match the raster file.
This is good news for me because it means that I can keep forceXY to true. However, I'm not sure that I completely understand what is going on.
I think it has something to do with the raster file being processed. When I try the clouds.jpg dataset available at the following link
It works with both shapefiles correctly with or without setting forceXY to true.

Thanks
Ahmed

On Tue, Jun 6, 2017 at 10:51 PM, Andrea Aime <[hidden email]> wrote:
Hi Ahmed,
I don't know what would happen, if you are interested you can try with a shapefile produced
by a WFS 1.1 server (which by spec should default to lat/lon order, even if the spec is not clear
about what to do with shapefiles).
For example, this is in lat/lon order:


QGIS for example ignores its explicit axis order and display it flipped, not sure what GeoTools will do.

Cheers
Andrea


On Wed, Jun 7, 2017 at 12:19 AM, Ahmed Eldawy <[hidden email]> wrote:
Thanks Andrea. I added that line and it fixed the problem. Is this going to break if a file uses YX ordering? It could be better to change the default to XY if it is not specified in the file, as in my case, but use the ordering specified in the file if it presents.

On Tue, Jun 6, 2017 at 11:07 AM, Andrea Aime <[hidden email]> wrote:
The shapefile in question does not define an axis order:

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]

As a result, GeoTools picks the order of international standards, which is lat/lon. However, shapefiles are normally encoded lon/lat...
Add this at the beginning of the file to force a "east/north" order:

System.setProperty("org.geotools.referencing.forceXY", "true");

The shapefile reader internal code should probably be forcing this order by default... although
care should be taken for those prj that do define an axis order. Needs some research, not a 5 minutes change.

Cheers
Andrea


On Tue, Jun 6, 2017 at 7:53 PM, Ahmed Eldawy <[hidden email]> wrote:
Hi all,

I am new to GeoTools. I was trying to load a file that represents all US states downloaded from here.
and the following GeoTIFF file

I also use the ImageLab example from GeoTools website to load the two files.

I use getools 17.0

What happens is that the shapefile is rotated 90 degrees. The same files are loaded correctly in QGIS. It happens with other files as well that are also loaded correctly in QGIS.

When I investigate the problem closely, I found that both files are loaded correctly. However, when the Shapefile is projected to the CoordinateReferenceSystem of the GeoTIFF file, the latitudes and longitudes are exchanged. This results in incorrect results when they are combined. Can you provide any help in why this problem happens and how I can solve it?

Best regards,
Ahmed Eldawy


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054  Massarosa (LU)
phone: <a href="tel:+39%200584%20962313" value="+390584962313" target="_blank">+39 0584 962313
fax: <a href="tel:+39%200584%20166%200272" value="+3905841660272" target="_blank">+39 0584 1660272
mob: <a href="tel:+39%20339%20884%204549" value="+393398844549" target="_blank">+39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------




--
==
GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.
==

Ing. Andrea Aime 
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via di Montramito 3/A
55054  Massarosa (LU)
phone: <a href="tel:+39%200584%20962313" value="+390584962313" target="_blank">+39 0584 962313
fax: <a href="tel:+39%200584%20166%200272" value="+3905841660272" target="_blank">+39 0584 1660272
mob: <a href="tel:+39%20339%20884%204549" value="+393398844549" target="_blank">+39  339 8844549


AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

 

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility  for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


-------------------------------------------------------


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
Ian Turton


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users