Java Code Examples for com.vividsolutions.jts.geom.CoordinateSequence#setOrdinate()

The following examples show how to use com.vividsolutions.jts.geom.CoordinateSequence#setOrdinate() . 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: GeoJsonReader.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CoordinateSequence createCoordinate(List<Number> ordinates) {
  CoordinateSequence result = new CoordinateArraySequence(1);

  if (ordinates.size() > 0) {
    result.setOrdinate(0, 0, ordinates.get(0).doubleValue());
  }
  if (ordinates.size() > 1) {
    result.setOrdinate(0, 1, ordinates.get(1).doubleValue());
  }
  if (ordinates.size() > 2) {
    result.setOrdinate(0, 2, ordinates.get(2).doubleValue());
  }

  return result;
}
 
Example 2
Source File: OraReader.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CoordinateSequence extractCoords(OraGeom oraGeom, double[] ordinates, int start, int end)
{
  CoordinateSequenceFactory csFactory = geometryFactory.getCoordinateSequenceFactory();
  // handle empty case
  if ((ordinates == null) || (ordinates.length == 0)) {
    return csFactory.create(new Coordinate[0]);
  }
  int ordDim = oraGeom.ordDim();
  
  /**
   * The dimension created matches the input dim, unless it is explicitly set,
   * and unless the CoordinateSequence impl limits the dimension.
   */
  int csDim = ordDim;
  if(outputDimension != OraGeom.NULL_DIMENSION){
	  csDim = outputDimension;
  }
  int nCoord = (ordDim == 0 ? 0 : (end - start) / ordDim);

  CoordinateSequence cs = csFactory.create(nCoord, csDim);
  int actualCSDim = cs.getDimension();
  int readDim = Math.min(actualCSDim, ordDim);
  
  for (int iCoord = 0; iCoord < nCoord; iCoord++) {
    for (int iDim = 0; iDim < readDim; iDim++) {
      int ordIndex = start + iCoord * ordDim + iDim - 1;
      // TODO: be more lenient in handling invalid ordinates length
      cs.setOrdinate(iCoord, iDim, ordinates[ordIndex]);
    }
  }
  return cs;
}
 
Example 3
Source File: BasicCoordinateSequenceTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testCloneDimension2() {
	CoordinateSequence s1 = CoordinateArraySequenceFactory.instance()
			.create(2, 2);
	s1.setOrdinate(0, 0, 1);
	s1.setOrdinate(0, 1, 2);
	s1.setOrdinate(1, 0, 3);
	s1.setOrdinate(1, 1, 4);

	CoordinateSequence s2 = (CoordinateSequence) CoordinateSequences.copy(s1);
	assertTrue(s1.getDimension() == s2.getDimension());
	assertTrue(s1.getCoordinate(0).equals(s2.getCoordinate(0)));
	assertTrue(s1.getCoordinate(0) != s2.getCoordinate(0));
}
 
Example 4
Source File: CoordinateSequenceTestBase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testCreateBySizeAndModify()
{
  Coordinate[] coords = createArray(SIZE);

  CoordinateSequence seq = getCSFactory().create(SIZE, 3);
  for (int i = 0; i < seq.size(); i++) {
    seq.setOrdinate(i, 0, coords[i].x);
    seq.setOrdinate(i, 1, coords[i].y);
    seq.setOrdinate(i, 2, coords[i].z);
  }

  assertTrue(isEqual(seq, coords));
}
 
Example 5
Source File: CoordinateSequenceTestBase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void test2DZOrdinate()
{
  Coordinate[] coords = createArray(SIZE);

  CoordinateSequence seq = getCSFactory().create(SIZE, 2);
  for (int i = 0; i < seq.size(); i++) {
    seq.setOrdinate(i, 0, coords[i].x);
    seq.setOrdinate(i, 1, coords[i].y);
  }

  for (int i = 0; i < seq.size(); i++) {
    Coordinate p = seq.getCoordinate(i);
    assertTrue(Double.isNaN(p.z));
  }
}