2

I am using Eclipse on Windows XP. I downloaded the GeoTools 2.7.4-bin.zip file and started to add some .jar files to my project. The particularity of my project is that this is an Android one.

I am developing an Android application that would allow me to show on a map (google map) some features (points but not only) so i tried to use GeoTools to do that.But Android is not supporting Swings. My code is

/*code i m using */

package info.ipower.geotools;

import java.io.File;

import org.geotools.data.FileDataStore;

import org.geotools.data.FileDataStoreFinder;

import org.geotools.data.simple.SimpleFeatureSource;

import org.geotools.map.FeatureLayer;

import org.geotools.map.Layer;

import org.geotools.map.MapContent;

import org.geotools.styling.SLD;

import org.geotools.styling.Style;

import org.geotools.swing.JMapFrame;

import org.geotools.swing.data.JFileDataStoreChooser;


/**
 * Prompts the user for a shapefile and displays the contents on the screen in a map frame.
 * <p>
 * This is the GeoTools MapApplication application used in documentationa and tutorials. *
 */

public class GeoMap{

    /**
     * GeoTools MapApplication demo application. Prompts the user for a shapefile and displays its
     * contents on the screen in a map frame
     */
    public static void main(String[] args) throws Exception {
        // display a data store file chooser dialog for shapefiles
        File file = JFileDataStoreChooser.showOpenFile("shp", null);
        if (file == null) {
            return;
        }

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();

        // Create a map content and add our shapefile to it
        MapContent map = new MapContent();
        map.setTitle("MapApplication");

        Style style = SLD.createSimpleStyle(featureSource.getSchema());
        Layer layer = new FeatureLayer(featureSource, style);
        map.addLayer(layer);

        // Now display the map
        JMapFrame.showMap(map);
    }

}

But it giving me following errors in eclipse

-The method showOpenFile(String, Component) from the type JFileDataStoreChooser refers to the missing type Component

  • The type java.awt.Component cannot be resolved. It is indirectly referenced from required .class files
  • The type java.awt.HeadlessException cannot be resolved. It is indirectly referenced from required .class files
  • The type javax.swing.JFileChooser cannot be resolved. It is indirectly referenced from required .class files
  • The method showMap(MapContext) in the type JMapFrame is not applicable for the arguments (MapContent)
  • The type javax.swing.JFrame cannot be resolved. It is indirectly referenced from required .class files Please any one help me to resolve these errors
Govindarao Kondala
  • 2,862
  • 17
  • 27
pravallika
  • 67
  • 2
  • 12

1 Answers1

3

Unfortunately Swing is not implemented on Android, so you are out of luck. In fact Oracle and Google just fought a big legal battle that was partially about this. I'm pretty sure that porting any serious Swing app or library to Android is a major effort: almost a rewrite from scratch.

Gene
  • 46,253
  • 4
  • 58
  • 96
  • Thanku for giving reply to me.but is it possible to display shape files with out using Swing concept? – pravallika Jun 25 '12 at 10:13
  • The error messages indicate that AWT and Swing are expected by the part of geotools you are trying to use. AWT and Swing aren't part of Android. So it's certain you can't use that part of the library. Perhaps other parts are usable. I can't say. – Gene Jun 25 '12 at 12:19
  • so,Is there any alternative method in android to display shape files?please help me. – pravallika Jun 25 '12 at 13:12
  • I don't know any except to write your own `Overlay` renderer in the Google Maps API. – Gene Jun 25 '12 at 13:42
  • can u help me to hide mapview and display overlay in googlemaps in android? – pravallika Sep 03 '12 at 13:47
  • There is Shapefile viewer/reader via OGR in Nutiteq Android toolkit, see https://github.com/nutiteq/hellomap3d/wiki/Ogr-layer. Disclaimer: I'm a developer of it. – JaakL Jun 10 '13 at 19:31