Java Code Examples for com.vividsolutions.jts.util.Assert#shouldNeverReachHere()

The following examples show how to use com.vividsolutions.jts.util.Assert#shouldNeverReachHere() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeometryEditor.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Geometry editInternal(Geometry geometry, GeometryEditorOperation operation)
{
  // if client did not supply a GeometryFactory, use the one from the input Geometry
  if (factory == null)
    factory = geometry.getFactory();

  if (geometry instanceof GeometryCollection) {
    return editGeometryCollection((GeometryCollection) geometry,
                                  operation);
  }

  if (geometry instanceof Polygon) {
    return editPolygon((Polygon) geometry, operation);
  }

  if (geometry instanceof Point) {
    return operation.edit(geometry, factory);
  }

  if (geometry instanceof LineString) {
    return operation.edit(geometry, factory);
  }

  Assert.shouldNeverReachHere("Unsupported Geometry class: " + geometry.getClass().getName());
  return null;
}
 
Example 2
Source File: GeometryEditorEx.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Geometry editInternal(Geometry geometry)
{
  // if client did not supply a GeometryFactory, use the one from the input Geometry
  if (targetFactory == null)
    targetFactory = geometry.getFactory();

  if (geometry instanceof GeometryCollection) {
    return editGeometryCollection((GeometryCollection) geometry);
  }
  if (geometry instanceof Polygon) {
    return editPolygon((Polygon) geometry);
  }
  if (geometry instanceof Point) {
    return editPoint((Point) geometry);
  }
  if (geometry instanceof LinearRing) {
    return editLinearRing((LinearRing) geometry);
  }
  if (geometry instanceof LineString) {
    return editLineString((LineString) geometry);
  }

  Assert.shouldNeverReachHere("Unsupported Geometry class: " + geometry.getClass().getName());
  return null;
}
 
Example 3
Source File: TestRunnerTestCaseAdapter.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public String getWellKnownText(int index) {
  if (index == 0) {
    if (testCase.getGeometryA() == null) {
      return null;
    }
    return wktWriter.write(testCase.getGeometryA());
  }
  else if (index == 1) {
    if (testCase.getGeometryB() == null) {
      return null;
    }
    return wktWriter.write(testCase.getGeometryB());
  }
  Assert.shouldNeverReachHere();
  return null;
}
 
Example 4
Source File: SameStructureTester.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static boolean isSameStructure(Geometry g1, Geometry g2)
{
  if (g1.getClass() != g2.getClass())
    return false;
  if (g1 instanceof GeometryCollection)
    return isSameStructureCollection((GeometryCollection) g1, (GeometryCollection) g2);
  else if (g1 instanceof Polygon)
    return isSameStructurePolygon((Polygon) g1, (Polygon) g2);
  else if (g1 instanceof LineString)
    return isSameStructureLineString((LineString) g1, (LineString) g2);
  else if (g1 instanceof Point)
    return isSameStructurePoint((Point) g1, (Point) g2);

  Assert.shouldNeverReachHere(
      "Unsupported Geometry class: " + g1.getClass().getName());
  return false;
}
 
Example 5
Source File: Vector2D.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Rotates a vector by a given number of quarter-circles (i.e. multiples of 90
 * degrees or Pi/2 radians). A positive number rotates counter-clockwise, a
 * negative number rotates clockwise. Under this operation the magnitude of
 * the vector and the absolute values of the ordinates do not change, only
 * their sign and ordinate index.
 * 
 * @param numQuarters
 *          the number of quarter-circles to rotate by
 * @return the rotated vector.
 */
public Vector2D rotateByQuarterCircle(int numQuarters) {
	int nQuad = numQuarters % 4;
	if (numQuarters < 0 && nQuad != 0) {
		nQuad = nQuad + 4;
	}
	switch (nQuad) {
	case 0:
		return create(x, y);
	case 1:
		return create(-y, x);
	case 2:
		return create(-x, -y);
	case 3:
		return create(y, -x);
	}
	Assert.shouldNeverReachHere();
	return null;
}
 
Example 6
Source File: GMLWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Writes a {@link Geometry} in GML2 format to a String.
 * 
 * @param geom
 * @return String GML2 Encoded Geometry
 */
public String write(Geometry geom) 
{
	StringWriter writer = new StringWriter();
	try {
		write(geom, writer);
	}
   catch (IOException ex) {
     Assert.shouldNeverReachHere();
   }
	return writer.toString();
}
 
Example 7
Source File: LineMergerTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Collection toGeometries(String[] inputWKT) {
  ArrayList geometries = new ArrayList();
  for (int i = 0; i < inputWKT.length; i++) {
    try {
      geometries.add(reader.read(inputWKT[i]));
    } catch (ParseException e) {
      Assert.shouldNeverReachHere();
    }
  }

  return geometries;
}
 
Example 8
Source File: WKTWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *  Same as <code>write</code>, but with newlines and spaces to make the
 *  well-known text more readable.
 *
 *@param  geometry  a <code>Geometry</code> to process
 *@return           a <Geometry Tagged Text> string (see the OpenGIS Simple
 *      Features Specification), with newlines and spaces
 */
public String writeFormatted(Geometry geometry)
{
  Writer sw = new StringWriter();
  try {
    writeFormatted(geometry, true, sw);
  }
  catch (IOException ex) {
    Assert.shouldNeverReachHere();
  }
  return sw.toString();
}
 
Example 9
Source File: TestCase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TestCase setExpectedBoundary(String wkt) {
  try {
    this.expectedBoundary = toNullOrGeometry(wkt);
  }
  catch (ParseException e) {
    Assert.shouldNeverReachHere();
  }
  return this;
}
 
Example 10
Source File: WKTWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *  Converts a <code>Geometry</code> to its Well-known Text representation.
 *
 *@param  geometry  a <code>Geometry</code> to process
 *@return           a <Geometry Tagged Text> string (see the OpenGIS Simple
 *      Features Specification)
 */
public String write(Geometry geometry)
{
  Writer sw = new StringWriter();
  try {
    writeFormatted(geometry, isFormatted, sw);
  }
  catch (IOException ex) {
    Assert.shouldNeverReachHere();
  }
  return sw.toString();
}
 
Example 11
Source File: TestCase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TestCase(String name, String description, String wkta, String wktb,
    String expectedIM, String expectedConvexHull, String expectedIntersection,
    String expectedUnion, String expectedDifference, String expectedSymDifference,
    String expectedBoundary) {
  try {
    init(name, description, wkta, wktb, expectedIM, toNullOrGeometry(expectedConvexHull),
        toNullOrGeometry(expectedIntersection), toNullOrGeometry(expectedUnion),
        toNullOrGeometry(expectedDifference), toNullOrGeometry(expectedSymDifference),
        toNullOrGeometry(expectedBoundary));
  }
  catch (ParseException e) {
    Assert.shouldNeverReachHere();
  }
}
 
Example 12
Source File: StringUtil.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static String getStackTrace(Throwable t, int depth) {
    String stackTrace = "";
    StringReader stringReader = new StringReader(getStackTrace(t));
    LineNumberReader lineNumberReader = new LineNumberReader(stringReader);
    for (int i = 0; i < depth; i++) {
        try {
            stackTrace += lineNumberReader.readLine() + newLine;
        } catch (IOException e) {
            Assert.shouldNeverReachHere();
        }
    }
    return stackTrace;
}
 
Example 13
Source File: SimpleReportWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void reportOnTest(Test test) 
{
  String id = test.getGeometryIndex() + " " + test.getOperation();
  for (int i = 0; i < test.getArgumentCount(); i++) {
    id += " " + test.getArgument(i);
  }
  if (test.getExpectedResult() instanceof BooleanResult) {
    id += ", " + test.getExpectedResult().toShortString();
  }
  if (test.getDescription().length() > 0) {
    id += ", " + test.getDescription();
  }
  String report = "";
  if (test.getException() != null) {
    reportBuf.write("Test Threw Exception (" + id + ")" + "     "
        + (verbose ? StringUtil.getStackTrace(test.getException()) : test.getException().toString()) + "\n"
        );
  }
  else if (test.isPassed() && verbose) {
    reportBuf.write("Test Passed (" + id + ")" + "\n");
  }
  else if (! test.isPassed()) {
    reportBuf.write("Test Failed (" + id + ")" + "\n");
    if (verbose) {
      reportBuf.write("  Expected: " + test.getExpectedResult().toFormattedString() + "\n");
      try {
        reportBuf.write("  Actual: " + test.getActualResult().toFormattedString() + "\n");
      }
      catch (Exception e) {
        Assert.shouldNeverReachHere(e.toString());
      }
    }
  }
}
 
Example 14
Source File: GeometryEditModel.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static String getText(Geometry geom, int textType) {
  switch (textType) {
    case GeometryType.WELLKNOWNTEXT:
      String wkt = wktWriter.writeFormatted(geom);
      return wkt;
  }
  Assert.shouldNeverReachHere();
  return "";
}
 
Example 15
Source File: XMLTestWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String getTestXML(Testable testable, boolean useWKT) {
  if (testable instanceof TestCase) {
    return getTestXML((TestCase)testable, useWKT);
  }
  if (testable instanceof TestCaseEdit) {
    return getTestXML(((TestCaseEdit)testable).getTestable(), useWKT);
  }
  if (testable instanceof TestRunnerTestCaseAdapter) {
    return getTestXML((TestRunnerTestCaseAdapter)testable, useWKT);
  }
  Assert.shouldNeverReachHere();
  return null;
}
 
Example 16
Source File: TestRunnerTestCaseAdapter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Result getDefaultResult(String opName) {
  if (GeometryMethodOperation.isBooleanFunction(opName)) {
    return new BooleanResult(true);
  }
  if (GeometryMethodOperation.isGeometryFunction(opName)) {
    return new GeometryResult(
    new GeometryFactory(testCase.getTestRun().getPrecisionModel(),
	0).createGeometryCollection(null));
  }
  Assert.shouldNeverReachHere();
  return null;
}
 
Example 17
Source File: WKTWriter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *  Converts a <code>Geometry</code> to &lt;Geometry Tagged Text&gt; format,
 *  then appends it to the writer.
 *
 *@param  geometry  the <code>Geometry</code> to process
 *@param  writer    the output writer to append to
 */
private void appendGeometryTaggedText(Geometry geometry, int level, Writer writer)
  throws IOException
{
  indent(level, writer);

  if (geometry instanceof Point) {
    Point point = (Point) geometry;
    appendPointTaggedText(point.getCoordinate(), level, writer, point.getPrecisionModel());
  }
  else if (geometry instanceof LinearRing) {
    appendLinearRingTaggedText((LinearRing) geometry, level, writer);
  }
  else if (geometry instanceof LineString) {
    appendLineStringTaggedText((LineString) geometry, level, writer);
  }
  else if (geometry instanceof Polygon) {
    appendPolygonTaggedText((Polygon) geometry, level, writer);
  }
  else if (geometry instanceof MultiPoint) {
    appendMultiPointTaggedText((MultiPoint) geometry, level, writer);
  }
  else if (geometry instanceof MultiLineString) {
    appendMultiLineStringTaggedText((MultiLineString) geometry, level, writer);
  }
  else if (geometry instanceof MultiPolygon) {
    appendMultiPolygonTaggedText((MultiPolygon) geometry, level, writer);
  }
  else if (geometry instanceof GeometryCollection) {
    appendGeometryCollectionTaggedText((GeometryCollection) geometry, level, writer);
  }
  else {
    Assert.shouldNeverReachHere("Unsupported Geometry implementation:"
         + geometry.getClass());
  }
}
 
Example 18
Source File: TestRunnerTestCaseAdapter.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setGeometry(int index, Geometry g) {
  if (index == 0) {
    testCase.setGeometryA(g);
  }
  else if (index == 1) {
    testCase.setGeometryB(g);
  }
  else {
    Assert.shouldNeverReachHere();
  }
}
 
Example 19
Source File: ExtractLineByLocation.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Geometry reverse(Geometry linear)
{
  if (linear instanceof LineString)
    return ((LineString) linear).reverse();
  if (linear instanceof MultiLineString)
    return ((MultiLineString) linear).reverse();
  Assert.shouldNeverReachHere("non-linear geometry encountered");
  return null;
}
 
Example 20
Source File: GeometryFactory.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 *  Build an appropriate <code>Geometry</code>, <code>MultiGeometry</code>, or
 *  <code>GeometryCollection</code> to contain the <code>Geometry</code>s in
 *  it.
 * For example:<br>
 *
 *  <ul>
 *    <li> If <code>geomList</code> contains a single <code>Polygon</code>,
 *    the <code>Polygon</code> is returned.
 *    <li> If <code>geomList</code> contains several <code>Polygon</code>s, a
 *    <code>MultiPolygon</code> is returned.
 *    <li> If <code>geomList</code> contains some <code>Polygon</code>s and
 *    some <code>LineString</code>s, a <code>GeometryCollection</code> is
 *    returned.
 *    <li> If <code>geomList</code> is empty, an empty <code>GeometryCollection</code>
 *    is returned
 *  </ul>
 *
 * Note that this method does not "flatten" Geometries in the input, and hence if
 * any MultiGeometries are contained in the input a GeometryCollection containing
 * them will be returned.
 *
 *@param  geomList  the <code>Geometry</code>s to combine
 *@return           a <code>Geometry</code> of the "smallest", "most
 *      type-specific" class that can contain the elements of <code>geomList</code>
 *      .
 */
public Geometry buildGeometry(Collection geomList) {
	
	/**
	 * Determine some facts about the geometries in the list
	 */
  Class geomClass = null;
  boolean isHeterogeneous = false;
  boolean hasGeometryCollection = false;
  for (Iterator i = geomList.iterator(); i.hasNext(); ) {
    Geometry geom = (Geometry) i.next();
    Class partClass = geom.getClass();
    if (geomClass == null) {
      geomClass = partClass;
    }
    if (partClass != geomClass) {
      isHeterogeneous = true;
    }
    if (geom instanceof GeometryCollection)
      hasGeometryCollection = true;
  }
  
  /**
   * Now construct an appropriate geometry to return
   */
  // for the empty geometry, return an empty GeometryCollection
  if (geomClass == null) {
    return createGeometryCollection(null);
  }
  if (isHeterogeneous || hasGeometryCollection) {
    return createGeometryCollection(toGeometryArray(geomList));
  }
  // at this point we know the collection is hetereogenous.
  // Determine the type of the result from the first Geometry in the list
  // this should always return a geometry, since otherwise an empty collection would have already been returned
  Geometry geom0 = (Geometry) geomList.iterator().next();
  boolean isCollection = geomList.size() > 1;
  if (isCollection) {
    if (geom0 instanceof Polygon) {
      return createMultiPolygon(toPolygonArray(geomList));
    }
    else if (geom0 instanceof LineString) {
      return createMultiLineString(toLineStringArray(geomList));
    }
    else if (geom0 instanceof Point) {
      return createMultiPoint(toPointArray(geomList));
    }
    Assert.shouldNeverReachHere("Unhandled class: " + geom0.getClass().getName());
  }
  return geom0;
}