EPSG Geodetic Parameter Dataset

The purpose of the EPSG Geodetic Parameter Dataset is to:

  • provide an unambiguous coordinate reference system (CRS), and
  • define transformations and conversions that allow coordinates to be changed from one CRS to another CRS

The EPSG Geodetic Parameter Dataset can be found at http://www.epsg.org/Geodetic.html

Setting Up the EPSG Geodetic Parameter Dataset Database

There are three (3) scripts that generate the necessary tables for the EPSG Geodetic Parameter Dataset. The following are the steps for installing on a PostgreSQL database:

Step 1:

Create the EPSG database:

#> createdb.exe -U postgres -E LATIN9 EPSG

NOTE: The database must be created with the LATIN9 charset.

Step 2:

Run the provided scripts in the following order:

#> psql.exe -U postgres EPSG < EPSG_v6_13.mdb_Tables_PostgreSQL.sql
#> psql.exe -U postgres EPSG < EPSG_v6_13.mdb_Data_PostgreSQL.sql
#> psql.exe -U postgres EPSG < EPSG_v6_13.mdb_FKeys_PostgreSQL.sql

Step 3:

Run the Postgres vacuum command:

#> vacuumdb.exe -U postgres -f -z EPSG

Using the Geotools PostgreDataSource

In our case we used Spring. Our Spring configuration file has the following entry:

<beans ...>
    <bean id="epsgPostgreDataSource" class="org.geotools.referencing.factory.epsg.PostgreDataSource">
        <constructor-arg index="0" type="java.lang.String" value="localhost"/>
        <constructor-arg index="1" type="java.lang.String" value="EPSG"/>
        <constructor-arg index="2"><null/></constructor-arg>
        <constructor-arg index="3" type="java.lang.String" value="postgres"/>
        <constructor-arg index="4" type="java.lang.String" value="password"/>

We can then use the datasource to force a CRS to our GeoTools geometry objects for use in shapefiles:

// get the datasource
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring-ds.xml");
    PostgreDataSource epsgPostgreDataSource = ctx..getBean("epsgPostgreDataSource");

    File file = new File("filename.shp");

    // Create a Map object used by our DataStore Factory
    Map<String, URL> map = Collections.singletonMap(URL, file.toURI().toURL());
    ShapefileDataStore dataStore = (ShapefileDataStore) new ShapefileDataStoreFactory().createNewDataStore(map);

    AbstractAuthorityFactory abstractAuthorityFactory = epsgPostgreDataSource.createFactory(null);

    FeatureType featureType = DataUtilities.createType(name, "geom:Polygon");
    // Create the Shapefile (empty at this point)

You now have a dataStore ready to which you can add features.

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply