Permalink
Browse files

Be consistent in EPSG vs Epsg

  • Loading branch information...
lossyrob committed Dec 5, 2016
1 parent 344946e commit 343588b4b066851ea6b35a7d9cc671f4a6d47f2c
@@ -22,7 +22,7 @@ import org.osgeo.proj4j._
import scala.io.Source
object CRS {
private lazy val proj4ToEPSGMap = new Memoize[String, Option[String]](readEPSGCodeFromFile)
private lazy val proj4ToEpsgMap = new Memoize[String, Option[String]](readEpsgCodeFromFile)
private val crsFactory = new CRSFactory
private val filePrefix = "/geotrellis/proj4/nad/"
@@ -42,14 +42,14 @@ object CRS {
new CRS {
val proj4jCrs = crsFactory.createFromParameters(null, proj4Params)
def epsgCode: Option[Int] = getEPSGCode(toProj4String + " <>")
def epsgCode: Option[Int] = getEpsgCode(toProj4String + " <>")
}
/**
* Returns the numeric EPSG code of a proj4string.
*/
def getEPSGCode(proj4String: String): Option[Int] =
proj4ToEPSGMap(proj4String).map(_.toInt)
def getEpsgCode(proj4String: String): Option[Int] =
proj4ToEpsgMap(proj4String).map(_.toInt)
/**
* Creates a CoordinateReferenceSystem
@@ -68,15 +68,15 @@ object CRS {
new CRS {
val proj4jCrs = crsFactory.createFromParameters(name, proj4Params)
def epsgCode: Option[Int] = getEPSGCode(toProj4String + " <>")
def epsgCode: Option[Int] = getEpsgCode(toProj4String + " <>")
}
/**
* Creates a CoordinateReferenceSystem (CRS) from a
* well-known-text String.
*/
def fromWKT(wktString: String): CRS = {
val epsgCode: String = WKT.getEPSGCode(wktString)
val epsgCode: String = WKT.getEpsgCode(wktString)
fromName(epsgCode)
}
@@ -110,7 +110,7 @@ object CRS {
new CRS {
val proj4jCrs = crsFactory.createFromName(name)
def epsgCode: Option[Int] = getEPSGCode(toProj4String + " <>")
def epsgCode: Option[Int] = getEpsgCode(toProj4String + " <>")
}
/**
@@ -119,7 +119,7 @@ object CRS {
def fromEpsgCode(epsgCode: Int) =
fromName(s"EPSG:$epsgCode")
private def readEPSGCodeFromFile(proj4String: String): Option[String] = {
private def readEpsgCodeFromFile(proj4String: String): Option[String] = {
val stream = getClass.getResourceAsStream(s"${filePrefix}epsg")
try {
Source.fromInputStream(stream)
@@ -160,7 +160,7 @@ trait CRS extends Serializable {
* Returns the WKT representation of the Coordinate Reference
* System.
*/
def toWKT(): Option[String] = epsgCode.map(WKT.fromEPSGCode(_))
def toWKT(): Option[String] = epsgCode.map(WKT.fromEpsgCode(_))
// TODO: Do these better once more things are ported
@@ -26,22 +26,22 @@ import scala.io.Source
*/
object WKT {
private lazy val epsgcodetowktmap = new Memoize[String, String](retrieveWKTStringFromFile)
private lazy val wkttoepsgcodemap = new Memoize[String, String](retrieveEPSGCodeFromFile)
private lazy val wkttoepsgcodemap = new Memoize[String, String](retrieveEpsgCodeFromFile)
private val wktResourcePath = "/geotrellis/proj4/wkt/epsg.properties"
/**
* Returns the WKT representation given an EPSG code in the format EPSG:[number]
* @param code
* @return
*/
def fromEPSGCode(code: Int): String = epsgcodetowktmap(code.toString)
def fromEpsgCode(code: Int): String = epsgcodetowktmap(code.toString)
/**
* Returns the numeric code of a WKT string given the authority
* @param wktString
* @return
*/
def getEPSGCode(wktString: String) = wkttoepsgcodemap(wktString)
def getEpsgCode(wktString: String) = wkttoepsgcodemap(wktString)
private def withWktFile[T](f: Iterator[String] => T) = {
val stream = getClass.getResourceAsStream(wktResourcePath)
@@ -73,7 +73,7 @@ object WKT {
* @param wktString
* @return
*/
private def retrieveEPSGCodeFromFile(wktString: String): String =
private def retrieveEpsgCodeFromFile(wktString: String): String =
withWktFile { lines =>
lines.find(_.split("=")(1) == wktString) match {
case Some(string) =>
@@ -23,19 +23,19 @@ import org.scalatest.FunSpec
*/
class WKTTest extends FunSpec {
it("should return the WKTString corresponding to EPSG:3824") {
val wktString = WKT.fromEPSGCode(3824)
val wktString = WKT.fromEpsgCode(3824)
assert(wktString == "GEOGCS[\"TWD97\", DATUM[\"Taiwan Datum 1997\", SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"7019\"]], TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], AUTHORITY[\"EPSG\",\"1026\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"3824\"]]")
}
it("should return the WKTString corresponding to EPSG:4326") {
val wktString = WKT.fromEPSGCode(4326)
val wktString = WKT.fromEpsgCode(4326)
assert(wktString == "GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4326\"]]")
}
it("should return the WKTString corresponding to EPSG:3857") {
val wktString = WKT.fromEPSGCode(3857)
val wktString = WKT.fromEpsgCode(3857)
assert(wktString == "PROJCS[\"WGS 84 / Pseudo-Mercator\", GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4326\"]], PROJECTION[\"Popular Visualisation Pseudo Mercator\", AUTHORITY[\"EPSG\",\"1024\"]], PARAMETER[\"semi_minor\", 6378137.0], PARAMETER[\"latitude_of_origin\", 0.0], PARAMETER[\"central_meridian\", 0.0], PARAMETER[\"scale_factor\", 1.0], PARAMETER[\"false_easting\", 0.0], PARAMETER[\"false_northing\", 0.0], UNIT[\"m\", 1.0], AXIS[\"Easting\", EAST], AXIS[\"Northing\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]")
}
@@ -44,23 +44,23 @@ class WKTTest extends FunSpec {
it("should return the EPSG code(3824) of the passed WKT string") {
val comparisonCode = "EPSG:3824"
val epsgCodeOfWKT = WKT.getEPSGCode("GEOGCS[\"TWD97\", DATUM[\"Taiwan Datum 1997\", SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"7019\"]], TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], AUTHORITY[\"EPSG\",\"1026\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"3824\"]]")
val epsgCodeOfWKT = WKT.getEpsgCode("GEOGCS[\"TWD97\", DATUM[\"Taiwan Datum 1997\", SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"7019\"]], TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], AUTHORITY[\"EPSG\",\"1026\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"3824\"]]")
assert(comparisonCode == epsgCodeOfWKT)
}
it("should return the EPSG code(4326) of the passed WKT string") {
val comparisonCode = "EPSG:4326"
val epsgCodeOfWKT = WKT.getEPSGCode("GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4326\"]]")
val epsgCodeOfWKT = WKT.getEpsgCode("GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4326\"]]")
assert(comparisonCode == epsgCodeOfWKT)
}
it("should return the EPSG code(3857) of the passed WKT string") {
val comparisonCode = "EPSG:3857"
val epsgCodeOfWKT = WKT.getEPSGCode("PROJCS[\"WGS 84 / Pseudo-Mercator\", GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4326\"]], PROJECTION[\"Popular Visualisation Pseudo Mercator\", AUTHORITY[\"EPSG\",\"1024\"]], PARAMETER[\"semi_minor\", 6378137.0], PARAMETER[\"latitude_of_origin\", 0.0], PARAMETER[\"central_meridian\", 0.0], PARAMETER[\"scale_factor\", 1.0], PARAMETER[\"false_easting\", 0.0], PARAMETER[\"false_northing\", 0.0], UNIT[\"m\", 1.0], AXIS[\"Easting\", EAST], AXIS[\"Northing\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]")
val epsgCodeOfWKT = WKT.getEpsgCode("PROJCS[\"WGS 84 / Pseudo-Mercator\", GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], AUTHORITY[\"EPSG\",\"6326\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4326\"]], PROJECTION[\"Popular Visualisation Pseudo Mercator\", AUTHORITY[\"EPSG\",\"1024\"]], PARAMETER[\"semi_minor\", 6378137.0], PARAMETER[\"latitude_of_origin\", 0.0], PARAMETER[\"central_meridian\", 0.0], PARAMETER[\"scale_factor\", 1.0], PARAMETER[\"false_easting\", 0.0], PARAMETER[\"false_northing\", 0.0], UNIT[\"m\", 1.0], AXIS[\"Easting\", EAST], AXIS[\"Northing\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]")
assert(comparisonCode == epsgCodeOfWKT)
}
}

0 comments on commit 343588b

Please sign in to comment.