Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * h2spatial is a library that brings spatial support to the H2 Java database.
   *
   * h2spatial is distributed under GPL 3 license. It is produced by the "Atelier SIG"
   * team of the IRSTV Institute <http://www.irstv.fr/> CNRS FR 2488.
   *
   * Copyright (C) 2007-2014 IRSTV (FR CNRS 2488)
   *
   * h2patial is free software: you can redistribute it and/or modify it under the
  * terms of the GNU General Public License as published by the Free Software
  * Foundation, either version 3 of the License, or (at your option) any later
  * version.
  *
  * h2spatial is distributed in the hope that it will be useful, but WITHOUT ANY
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License along with
  * h2spatial. If not, see <http://www.gnu.org/licenses/>.
  *
  * For more information, please consult: <http://www.orbisgis.org/>
  * or contact directly:
  * info_at_ orbisgis.org
  */
 /*
  *    GeoTools - OpenSource mapping toolkit
  *    http://geotools.org
  *    (C) 2002-2006, Geotools Project Managment Committee (PMC)
  *    (C) 2002, Centre for Computational Geography
  *
  *    This library is free software; you can redistribute it and/or
  *    modify it under the terms of the GNU Lesser General Public
  *    License as published by the Free Software Foundation; either
  *    version 2.1 of the License, or (at your option) any later version.
  *
  *    This library is distributed in the hope that it will be useful,
  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  *    Lesser General Public License for more details.
  */
 package org.h2gis.drivers.shp.internal;
 
 

Author(s):
aaime
Ian Schneider
See also:
"http://svn.geotools.org/geotools/tags/2.3.1/plugin/shapefile/src/org/geotools/data/shapefile/shp/MultiPointHandler.java"
 
 public class MultiPointHandler implements ShapeHandler {
 
         final ShapeType shapeType;
         GeometryFactory geometryFactory = new GeometryFactory();

        
Creates new MultiPointHandler
 
         public MultiPointHandler() {
                  = .;
         }
 
         public MultiPointHandler(ShapeType typethrows ShapefileException {
                 if ((type != .) && (type != .) && (type != .)) {
                         throw new ShapefileException(
                                 "Multipointhandler constructor - expected type to be 8, 18, or 28");
                 }
 
                  = type;
         }

        
Returns the shapefile shape type value for a point

Returns:
int Shapefile.POINT
 
         @Override
         public ShapeType getShapeType() {
                 return ;
         }

        
Calcuates the record length of this object.

Returns:
int The length of the record that this shapepoint will take up in a shapefile
 
         @Override
         public int getLength(Object geometry) {
                 MultiPoint mp = (MultiPointgeometry;
 
                 int length;
 
                 if ( == .) {
                        // two doubles per coord (16 * numgeoms) + 40 for header
                        length = (mp.getNumGeometries() * 16) + 40;
                } else if ( == .) {
                        // add the additional MMin, MMax for 16, then 8 per measure
                        length = (mp.getNumGeometries() * 16) + 40 + 16 + (8 * mp.getNumGeometries());
                } else if ( == .) {
                        // add the additional ZMin,ZMax, plus 8 per Z
                        length = (mp.getNumGeometries() * 16) + 40 + 16 + (8 * mp.getNumGeometries()) + 16
                                + (8 * mp.getNumGeometries());
                } else {
                        throw new IllegalStateException("Expected ShapeType of Arc, got " + );
                }
                return length;
        }
        @Override
        public Geometry read(ReadBufferManager bufferShapeType typethrows IOException {
                if (type == .) {
                        return null;
                }
                //read bounding box (not needed)
                buffer.skip(4 * 8);
                int numpoints = buffer.getInt();
                Coordinate[] coords = new Coordinate[numpoints];
                for (int t = 0; t < numpointst++) {
                        double x = buffer.getDouble();
                        double y = buffer.getDouble();
                        coords[t] = new Coordinate(xy);
                }
                if ( == .) {
                        buffer.skip(2 * 8);
                        for (int t = 0; t < numpointst++) {
                                coords[t]. = buffer.getDouble(); //z
                        }
                }
                return .createMultiPoint(coords);
        }
        @Override
        public void write(WriteBufferManager bufferObject geometrythrows IOException {
                MultiPoint mp = (MultiPointgeometry;
                Envelope box = mp.getEnvelopeInternal();
                buffer.putDouble(box.getMinX());
                buffer.putDouble(box.getMinY());
                buffer.putDouble(box.getMaxX());
                buffer.putDouble(box.getMaxY());
                buffer.putInt(mp.getNumGeometries());
                for (int t = 0, tt = mp.getNumGeometries(); t < ttt++) {
                        Coordinate c = (mp.getGeometryN(t)).getCoordinate();
                        buffer.putDouble(c.x);
                        buffer.putDouble(c.y);
                }
                if ( == .) {
                        double[] zExtreame = CoordinatesUtils.zMinMax(mp.getCoordinates());
                        if (Double.isNaN(zExtreame[0])) {
                                buffer.putDouble(0.0);
                                buffer.putDouble(0.0);
                        } else {
                                buffer.putDouble(zExtreame[0]);
                                buffer.putDouble(zExtreame[1]);
                        }
                        for (int t = 0; t < mp.getNumGeometries(); t++) {
                                Coordinate c = (mp.getGeometryN(t)).getCoordinate();
                                double z = c.z;
                                if (Double.isNaN(z)) {
                                        buffer.putDouble(0.0);
                                } else {
                                        buffer.putDouble(z);
                                }
                        }
                }
                if ( == . ||  == .) {
                        buffer.putDouble(-10E40);
                        buffer.putDouble(-10E40);
                        for (int t = 0; t < mp.getNumGeometries(); t++) {
                                buffer.putDouble(-10E40);
                        }
                }
        }
New to GrepCode? Check out our FAQ X