Pages

Friday, 30 May 2008

How to look up the EPSG code for a CoordinateReferenceSystem

Today's question comes for the uDig developers list; this is a fairly classic problem - shapefile store their CoordinateReferneceSystem definition as a .prj file, containing "Well-Known-Text". How can you look up the "official" EPSG code for a CoordinateReferenceSystem? And why would you want to?

A CoordinateReferenceSystem generated from "raw" WKT:
  • Often does not have an EPSG code. These codes are useful to know when working with data from a range of sources. If we can figure out the code we can construct a WMS GetMap request (for a base map layer) that matches the shapefile.
  • Often lacks some of the meta-data used when creating a good MathTransform
Here is how to look up an "official" CoordinateReferenceSystem.
  1. Construct a CoordinateReferenceSystem based on what you have.
    String name = "ED50";
    String wkt =
    "GEOGCS[\"" + name + "\",\n" +
    " DATUM[\"European Datum 1950\",\n" +
    " SPHEROID[\"International 1924\", 6378388.0, 297.0]],\n" +
    "PRIMEM[\"Greenwich\", 0.0],\n" +
    "UNIT[\"degree\", 0.017453292519943295]]";
    CoordianteReferenceSystem example = CRS.parseWKT(wkt);
  2. Find the Identifier for your CoordinateReferenceSystem
    String code = CRS.lookupIdentifier( example, true ); // should be "EPSG:4230
  3. Look up the official definition for that Identifier
    CoordinateReferenceSystem crs = CRS.decode( code );
You will find the official CoordinateReferenceSystem is much better at generating MathTransforms.
CoordianteReferenceSystem wsg84 = CRS.decode( "EPSG:4326" );
MathTransform transform = CRS.findMathTransform(crs, wsg84, true);
Geometry targetGeometry = JTS.transform( sourceGeometry, transform );
If you do have any trouble - set the lenient flag to false, the transform will no longer be as accurate (as WKT by itself does not have enough information to account for datum shifts etc...).
CoordianteReferenceSystem wsg84 = CRS.decode( "EPSG:4326" );
MathTransform transform = CRS.findMathTransform(example, wsg84, false );
Geometry targetGeometry = JTS.transform( sourceGeometry, transform );
Documentation harmed in the making of this post:

20 comments:

sheela rajesh said...


I have to appreciate you for your great work which you had done in your blog.i want you to add more like this.
JAVA Training in Chennai
Best JAVA Training institute in Chennai
SEO training in chennai
Python Training in Chennai
Selenium Training in Chennai
Big data training in chennai
Selenium Training in Chennai
JAVA Training in Chennai
Java Training in Anna Nagar

Anjali Vinu said...

I want to thank for sharing this article and I have bookmarked this page to check out new stuff.
Tally course in Chennai
Tally classes in Chennai
Tally Training in Chennai
GST classes in Chennai
PHP Training in Chennai
Salesforce Training in Chennai
Web Designing course in Chennai
CCNA course in Chennai
Tally Course in Velachery
Tally Course in Tambaram

Ravi said...


You write this post very carefully I think, which is easily understand to me. Not only this, other post is also good. As a newbie this info is really helpful for me. Thanks to you.
Tally Training in Chennai
Tally ERP 9 Training
tally classes
Tally Training institute in Chennai
Tally course in Chennai

Ravi said...


This content of information has
helped me a lot. It is very well explained and easy to understand.
seo training classes
seo training course
seo training institute in chennai
seo training institutes
seo courses in chennai
seo institutes in chennai
seo classes in chennai
seo training center in chennai

cathrine juliet said...

Every day I always visit sites to obtain the best information for materials research I was doing.......

Big Data Hadoop Training In Chennai | Big Data Hadoop Training In anna nagar | Big Data Hadoop Training In omr | Big Data Hadoop Training In porur | Big Data Hadoop Training In tambaram | Big Data Hadoop Training In velachery


Professional Course said...

I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.

Business Analytics Course in Bangalore

Data Analytics Course said...

Happy to chat on your blog, I feel like I can't wait to read more reliable posts and think we all want to thank many blog posts to share with us.

Data Analytics Course in Bangalore

Alwin Co Daan said...

Great Article
Java Projects for Engineering Students

IEEE projects

for CSE 2020


JavaScript Training in Chennai

JavaScript

Training in Chennai

Aishwariya said...

Thank you for sharing your article. Great efforts put it to find the list of articles which is very useful to know, Definitely will share the same to other forums. Amazon Web Services Training in Chennai

Professional Course said...

I really enjoyed reading your blog. It was very well written and easy to understand. Unlike other blogs that I have read which are actually not very good. Thank you so much!

Data Science Training in Bangalore

Digital Marketing Training in Bangalore said...

Really wonderful blog completely enjoyed reading and learning to gain vast knowledge. Eventually, this blog helps in developing certain skills which in turn helpful in implementing those skills. Thanking the blogger for delivering such beautiful content and keep posting the contents in the upcoming days.

Digital Marketing Training in Bangalore

Machine Learning Course in Bangalore said...

The Extraordinary blog went amazed with the content that they have developed in a very descriptive manner. This type of content surely ensures the participants explore themselves. Hope you deliver the same near the future as well. Gratitude to the blogger for the efforts.

Machine Learning Course in Bangalore

Professional Course said...

It is late to find this act. At least one should be familiar with the fact that such events exist. I agree with your blog and will come back to inspect it further in the future, so keep your performance going.

Digital Marketing Training in Bangalore

Training Institute said...

A good blog always contains new and exciting information, and reading it I feel like this blog really has all of these qualities that make it a blog.

Artificial Intelligence Training in Bangalore

Machine Learning Course in BLR said...

I am more curious to take an interest in some of them. I hope you will provide more information on these topics in your next articles.

Machine Learning Course in Bangalore

Professional Course said...

I will very much appreciate the writer's choice for choosing this excellent article suitable for my topic. Here is a detailed description of the topic of the article that helped me the most.

Artificial Intelligence Course in Bangalore

Professional Course said...

It's a smart blog. I mean it seriously. You have so much knowledge on this subject and so much passion. He also knows how to get people to join him, obviously from the answers.

Data Science Course in Nagpur

Professional Course said...

Its content is brilliant in many ways. I think it is an attractive and revealing material. Thank you very much for caring about your content and your readers.

Business Analytics Course in Patna

Professional Course said...

Happy to chat on your blog, I feel like I can't wait to read more reliable posts and think we all want to thank many blog posts to share with us.

Data Science in Bangalore

Professional Course said...

I really appreciate this wonderful message you have given us. I assure you that would be beneficial for most people.

Data Analytics Course in Nagpur