Exemplo n.º 1
0
  /**
   * Read the shapefile
   *
   * @param shapefile shapefile
   * @param bbox _more_
   * @return List of point sets
   */
  private List doRead(EsriShapefile shapefile, Rectangle2D bbox) {

    this.shapefile = shapefile;
    List features = shapefile.getFeatures();
    java.util.Iterator si = features.iterator();
    dbFile = shapefile.getDbFile();
    List s0 = new ArrayList();

    int pointCnt = 0;
    for (int i = 0; si.hasNext(); i++) {
      EsriShapefile.EsriFeature gf = (EsriShapefile.EsriFeature) si.next();
      SampledSet mapLines = gf.getMapLines(bbox);
      pointCnt += gf.getPointCount();
      if (mapLines != null) {
        s0.add(mapLines);
      }
    }
    return s0;
  }
  /**
   * @param request _more_
   * @param entry _more_
   * @param map _more_
   * @return _more_
   */
  @Override
  public boolean addToMap(Request request, Entry entry, MapInfo map) {
    try {
      if (!entry.isFile()) {
        return true;
      }
      // TODO: stream through the shapes
      EsriShapefile shapefile = new EsriShapefile(entry.getFile().toString());
      List features = shapefile.getFeatures();
      int totalPoints = 0;
      int MAX_POINTS = 10000;
      for (int i = 0; i < features.size(); i++) {
        if (totalPoints > MAX_POINTS) {
          break;
        }
        EsriShapefile.EsriFeature gf = (EsriShapefile.EsriFeature) features.get(i);
        java.util.Iterator pi = gf.getGisParts();
        while (pi.hasNext()) {
          if (totalPoints > MAX_POINTS) {
            break;
          }
          GisPart gp = (GisPart) pi.next();
          double[] xx = gp.getX();
          double[] yy = gp.getY();
          List<double[]> points = new ArrayList<double[]>();
          for (int ptIdx = 0; ptIdx < xx.length; ptIdx++) {
            points.add(new double[] {yy[ptIdx], xx[ptIdx]});
          }
          totalPoints += points.size();
          if (points.size() > 1) {
            map.addLines("", points);
          } else if (points.size() == 1) {
            map.addMarker("id", points.get(0)[0], points.get(0)[1], null, "");
          }
        }
      }
    } catch (Exception exc) {
      throw new RuntimeException(exc);
    }

    return false;
  }
 /**
  * _more_
  *
  * @param request _more_
  * @param entry _more_
  * @param parent _more_
  * @param newEntry _more_
  * @throws Exception _more_
  */
 public void initializeEntryFromForm(Request request, Entry entry, Entry parent, boolean newEntry)
     throws Exception {
   if (!entry.isFile()) {
     return;
   }
   EsriShapefile shapefile = new EsriShapefile(entry.getFile().toString());
   Rectangle2D bounds = shapefile.getBoundingBox();
   double[][] lonlat = new double[][] {{bounds.getX()}, {bounds.getY() + bounds.getHeight()}};
   ProjFile projFile = shapefile.getProjFile();
   if (projFile != null) {
     lonlat = projFile.convertToLonLat(lonlat);
   }
   entry.setNorth(lonlat[IDX_LAT][0]);
   entry.setWest(lonlat[IDX_LON][0]);
   lonlat[IDX_LAT][0] = bounds.getY();
   lonlat[IDX_LON][0] = bounds.getX() + bounds.getWidth();
   if (projFile != null) {
     lonlat = projFile.convertToLonLat(lonlat);
   }
   entry.setSouth(lonlat[IDX_LAT][0]);
   entry.setEast(lonlat[IDX_LON][0]);
 }
Exemplo n.º 4
0
 /**
  * What is the feature type
  *
  * @return Feature type
  */
 public int getFeatureType() {
   if (shapefile != null) {
     return shapefile.getFeatureType();
   }
   return EsriShapefile.POLYGON;
 }