Class MultiLineString

  1 /*
  2  * Copyright (c) 2016 Vivid Solutions.
  3  *
  4  * All rights reserved. This program and the accompanying materials
  5  * are made available under the terms of the Eclipse Public License 2.0
  6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
  7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
  8  * and the Eclipse Distribution License is available at
  9  *
 10  * http://www.eclipse.org/org/documents/edl-v10.php.
 11  */
 12 package org.locationtech.jts.geom;
 13  
 14 import org.locationtech.jts.operation.BoundaryOp;
 15  
 16 /**
 17  * Models a collection of {@link LineString}s.
 18  * <p>
 19  * Any collection of LineStrings is a valid MultiLineString.
 20  *
 21  *@version 1.7
 22  */
 23 public class MultiLineString
 24     extends GeometryCollection
 25     implements Lineal
 26     {
 27   private static final long serialVersionUID = 8166665132445433741L;
 28   /**
 29    *  Constructs a <code>MultiLineString</code>.
 30    *
 31    *@param  lineStrings     the <code>LineString</code>s for this <code>MultiLineString</code>
 32    *      , or <code>null</code> or an empty array to create the empty geometry.
 33    *      Elements may be empty <code>LineString</code>s, but not <code>null</code>
 34    *      s.
 35    *@param  precisionModel  the specification of the grid of allowable points
 36    *      for this <code>MultiLineString</code>
 37    *@param  SRID            the ID of the Spatial Reference System used by this
 38    *      <code>MultiLineString</code>
 39    * @deprecated Use GeometryFactory instead
 40    */
 41   public MultiLineString(LineString[] lineStrings, PrecisionModel precisionModel, int SRID) {
 42     super(lineStrings, new GeometryFactory(precisionModel, SRID));
 43   }
 44  
 45  
 46  
 47   /**
 48    * @param lineStrings
 49    *            the <code>LineString</code>s for this <code>MultiLineString</code>,
 50    *            or <code>null</code> or an empty array to create the empty
 51    *            geometry. Elements may be empty <code>LineString</code>s,
 52    *            but not <code>null</code>s.
 53    */
 54   public MultiLineString(LineString[] lineStrings, GeometryFactory factory) {
 55     super(lineStrings, factory);
 56   }
 57  
 58   public int getDimension() {
 59     return 1;
 60   }
 61  
 62   public int getBoundaryDimension() {
 63     if (isClosed()) {
 64       return Dimension.FALSE;
 65     }
 66     return 0;
 67   }
 68  
 69   public String getGeometryType() {
 70     return Geometry.TYPENAME_MULTILINESTRING;
 71   }
 72  
 73   public boolean isClosed() {
 74     if (isEmpty()) {
 75       return false;
 76     }
 77     for (int i = 0; i < geometries.length; i++) {
 78       if (!((LineString) geometries[i]).isClosed()) {
 79         return false;
 80       }
 81     }
 82     return true;
 83   }
 84  
 85   /**
 86    * Gets the boundary of this geometry.
 87    * The boundary of a lineal geometry is always a zero-dimensional geometry (which may be empty).
 88    *
 89    * @return the boundary geometry
 90    * @see Geometry#getBoundary
 91    */
 92   public Geometry getBoundary()
 93   {
 94     return (new BoundaryOp(this)).getBoundary();
 95   }
 96  
 97   /**
 98    * Creates a {@link MultiLineString} in the reverse
 99    * order to this object.
100    * Both the order of the component LineStrings
101    * and the order of their coordinate sequences
102    * are reversed.
103    *
104    * @return a {@link MultiLineString} in the reverse order
105    */
106   public MultiLineString reverse() {
107     return (MultiLineString) super.reverse();
108   }
109  
110   protected MultiLineString copyInternal() {
111     LineString[] lineStrings = new LineString[this.geometries.length];
112     for (int i = 0; i < lineStrings.length; i++) {
113       lineStrings[i] = (LineString) this.geometries[i].copy();
114     }
115     return new MultiLineString(lineStrings, factory);
116   }
117  
118   public boolean equalsExact(Geometry other, double tolerance) {
119     if (!isEquivalentClass(other)) {
120       return false;
121     }
122     return super.equalsExact(other, tolerance);
123   }
124  
125   protected int getTypeCode() {
126     return Geometry.TYPECODE_MULTILINESTRING;
127   }
128 }
129  
130