August Town: Using Java Map Projection Library in Android

Recently I was writing a little mapping application on Android, which basically takes Open Street Map tiles as base layer, and also has the ability to overlay some vector features on top. In this application there is need to convert coordinates back and forth between WGS84 and Mercator projection, so I need certain library to do the job. Given the popularity of (name it “PROJ4Java” below), seems to be an obvious choice so I spend some hours during the weekend to see how it works. . The size of the library is very small and lightweight with only 1.17MB for complete source code and 247KB for compiled jar file. If you’re familiar with PROJ.4 itself then this Java version should be quite straight forward, otherwise there isn’t much sample code or tutorial on its homepage. But the basic workflow is quite simple as described by its project homepage: To use the library, you need to create a projection, either directly by calling its constructor or via one of the factory methods. Once you have a Projection, you can use it to convert between latitude/longitude and projected map units (by default, metres) by calling the transform and transformInverse methods. A major issue of using PROJ4Java on Android is that out of box it can’t be run due to the fact that it is using some classes in java.awt.geom.* which is not available in Android SDK. But since the only major AWT class used by PROJ4Java is Point2D, it’s not difficult at all to work around by replacing it with your own 2D point class. In my case I use the point class from JTS library. After taking out all Java awt class references from source code and replacing them with JTS class, everything works pretty well on Android. Another thing I modifies on the source code is to get rid of those projection implementations I don’t need. Mercator projection is the only one I need so far so that I am able to reduce the size of compile jar file to only 168KB. Here is a list of classes I extracted from original source code to support only Mercator projection: ProjectionFactory class is the entry point for you to use PROJ4Java, which provides several static methods to create an instance of Projection. Below are some use cases I figured out by briefly reading through the source code: (1) ProjectionFactory.getNamedPROJ4CoordinateSystem(String name) takes a well-known projection code like “epsg:4326” and returns a Projection: (2) ProjectionFactory.fromPROJ4Specification(String[] params) takes a set of PROJ.4 parameters and returns a Projection: (3) Create an instance of customized projection. All supported projection definition strings (PROJ.4 parameters for ) for PROJ4Java are listed in text files under folder “nad” that is coming with the library. These files are “epsg”, “esri”, “nad27”, “nad83”, and “world”, and a sample projection definition string is like below: 1: <,2965>, +proj=tmerc +lat_0=37.5 +lon_0=-85.66666666666667 +k=0.999966667 +x_0=99999.99989839978 +y_0=249999.9998983998 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs To add a new customized projection just create a definition string (usually modify certain parameter values upon an existing projection) and add it into one of those files, or create a new text file under “nad” folder with the definition string, then use the code below: I am using the above code to convert the lat/lon to another projection , but while passing the params it is givving error as a null pointer exception , could u tell me whatis the mistake I have made available a JAR compatible with Android with references to AWT classes removed. It contains source as well as .class files and is available at I am facing an issue in my app i.e. suppose i have a map view and a list view, i select an area to be searched in map view but do the actual search in list view, now i get lots of deal in response but only those POIs will be displayed which fall under the currently selected area in map view, i dont want to use the mapview projection because it can change even if someone zoom and pan around but dint select the area to search (or the final area to be searched is not changed for me but the projections has changed) so now it can affect my POIs to be displayed in list view. The airport has GPS coordinates of - 82.89188888, 39.99797222 but the inverseTransform is returning -81.3929566, 38.12116. do you know how to create the transform point, because when i define the point var the softwre calls a library that not recognize. Source.


Яндекс.Метрика Рейтинг@Mail.ru Free Web Counter
page counter
Last Modified:
Fatal error: Call to undefined function mdv_last_modified() in /home1/wacedu0abjm6/public_html/wp-content/themes/CherryFramework/footer.php on line 121