CoordinateSequence* WKTReader::getCoordinates(StringTokenizer *tokenizer) { string nextToken=getNextEmptyOrOpener(tokenizer); if (nextToken=="EMPTY") { return geometryFactory->getCoordinateSequenceFactory()->create(NULL); //new CoordinateArraySequence(); } CoordinateSequence *coordinates = \ geometryFactory->getCoordinateSequenceFactory()->create(NULL); Coordinate coord; getPreciseCoordinate(tokenizer, coord); coordinates->add(coord); try { nextToken=getNextCloserOrComma(tokenizer); while (nextToken==",") { getPreciseCoordinate(tokenizer, coord); coordinates->add(coord); nextToken=getNextCloserOrComma(tokenizer); } } catch (...) { delete coordinates; throw; } return coordinates; }
void coordinateSeq3() { CoordinateSequence *cl = new CoordinateArraySequence(); cl->add(Coordinate(116.5189446,39.9385391)); cl->add(Coordinate(116.5389472,39.9386038)); cl->add(Coordinate(116.5589889,39.9387932)); cl->add(Coordinate(116.5789501,39.9386662)); cl->add(Coordinate(116.5889538,39.9387273)); cl->add(Coordinate(116.5289589,39.2387832)); cl->add(Coordinate(116.548965,39.9388347)); cl->add(Coordinate(116.5689136,39.9385191)); cl->add(Coordinate(116.5089711,39.9388873)); cl->add(Coordinate(116.5459744,39.9389397)); cl->add(Coordinate(116.5819436,39.9385291)); MultiPoint *mp = global_factory->createMultiPoint(*cl); prep::PreparedGeometry const *pg_ = prep::PreparedGeometryFactory::prepare(mp); pg_->getGeometry(); CoordinateSequence *cr = new CoordinateArraySequence(); cr->add(Coordinate(116.5889539 + 0.000005, 39.9387274 + 0.000005)); cr->add(Coordinate(116.5889539 + 0.000005, 39.9387274 - 0.000005)); cr->add(Coordinate(116.5889539 - 0.000005, 39.9387274 - 0.000005)); cr->add(Coordinate(116.5889539 - 0.000005, 39.9387274 + 0.000005)); cr->add(Coordinate(116.5889539 + 0.000005, 39.9387274 + 0.000005)); MultiPoint *mp2 = global_factory->createMultiPoint(*cr); LinearRing *li = global_factory->createLinearRing(cr); geos::geom::Polygon *poly1=global_factory->createPolygon(li,NULL); //geos::geom::Geometry *pint = mp2->intersection(mp); //geos::geom::Geometry *pint = mp2->intersection(poly1); geos::geom::Geometry *pint = pg_->getGeometry().intersection(poly1); //CoordinateSequence *coord = pint->getCoordinates(); CoordinateSequence *coord = pg_->getGeometry().getCoordinates(); printf("getNumPoints: %lu\n", pint->getNumPoints()); printf("Get CoordinateSequence Num: %lu\n", coord->getSize()); for (int i=0; i<coord->getSize(); i++) { printf("Get CoordinateSequence [%d]-(%f, %f)\n", i, coord->getX(i), coord->getY(i)); } delete coord; delete pint; delete mp; delete mp2; delete cl; delete cr; }
void coordinateSeq() { CoordinateSequence *cl = new CoordinateArraySequence(); cl->add(Coordinate(100,100)); cl->add(Coordinate(100,200)); cl->add(Coordinate(200,200)); cl->add(Coordinate(200,100)); cl->add(Coordinate(180,180)); //cl->add(Coordinate(100,100)); cl->add(geos::geom::Coordinate(150, 150)); cl->add(geos::geom::Coordinate(190, 190)); cl->add(geos::geom::Coordinate(150, 250)); cl->add(geos::geom::Coordinate(250, 250)); cl->add(geos::geom::Coordinate(250, 150)); //cl->add(geos::geom::Coordinate(150, 150)); LinearRing *lr = global_factory->createLinearRing(cl); geos::geom::Polygon *poly=NULL; poly = global_factory->createPolygon(lr,NULL); CoordinateSequence *cr = new CoordinateArraySequence(); cr->add(geos::geom::Coordinate(120, 120)); cr->add(geos::geom::Coordinate(120, 170)); cr->add(geos::geom::Coordinate(170, 170)); cr->add(geos::geom::Coordinate(170, 120)); //cr->add(geos::geom::Coordinate(120, 120)); LinearRing *li = global_factory->createLinearRing(cr); geos::geom::Polygon *poly1=global_factory->createPolygon(li,NULL); geos::geom::Geometry *pint = poly1->intersection(poly); io::WKTWriter *wkt = new io::WKTWriter(); string tmp=wkt->write(pint); cout<<" (WKT coordinateSeq Intersection) "<<tmp<<endl; }
void object::test<1>() { CoordinateSequence* cs = new CoordinateArraySequence(); cs->add(Coordinate(0.0, 0.0)); cs->add(Coordinate(1.0, DoubleNotANumber)); GeomPtr line ( factory_.createLineString(cs) ); IsValidOp isValidOp(line.get()); bool valid = isValidOp.isValid(); TopologyValidationError* err = isValidOp.getValidationError(); ensure(0 != err); const Coordinate& errCoord = err->getCoordinate(); ensure_equals( err->getErrorType(), TopologyValidationError::eInvalidCoordinate ); ensure(0 != ISNAN(errCoord.y)); ensure_equals(valid, false); }
// This function will create a LinearString // geometry with the shape of the letter U // having top-left corner at given coordinates // and 'side' height and width LineString * create_ushaped_linestring(double xoffset, double yoffset, double side) { // We will use a coordinate list to build the linestring CoordinateSequence *cl = new CoordinateArraySequence(); cl->add(Coordinate(xoffset, yoffset)); cl->add(Coordinate(xoffset, yoffset+side)); cl->add(Coordinate(xoffset+side, yoffset+side)); cl->add(Coordinate(xoffset+side, yoffset)); // Now that we have a CoordinateSequence we can create // the linestring. // The newly created LineString will take ownership // of the CoordinateSequence. LineString *ls = global_factory->createLineString(cl); // This is what you do if you want the new LineString // to make a copy of your CoordinateSequence: // LineString *ls = global_factory->createLineString(*cl); return ls; // our LineString }
void coordinateSeq2() { CoordinateSequence *cl = new CoordinateArraySequence(); cl->add(Coordinate(100,100)); cl->add(Coordinate(100,200)); cl->add(Coordinate(200,200)); cl->add(Coordinate(200,100)); cl->add(Coordinate(180,180)); cl->add(Coordinate(100,100)); LinearRing *lr = global_factory->createLinearRing(cl); geos::geom::Polygon *poly=NULL; poly = global_factory->createPolygon(lr,NULL); CoordinateSequence *cr = new CoordinateArraySequence(); cr->add(geos::geom::Coordinate(150, 150)); cr->add(geos::geom::Coordinate(190, 190)); cr->add(geos::geom::Coordinate(150, 250)); cr->add(geos::geom::Coordinate(250, 250)); cr->add(geos::geom::Coordinate(250, 150)); cr->add(geos::geom::Coordinate(150, 150)); //geos::geom::Polygon *poly1 = create_circle(150, 150, 10); LinearRing *li = global_factory->createLinearRing(cr); geos::geom::Polygon *poly1=global_factory->createPolygon(li,NULL); geos::geom::Geometry *pint = poly1->intersection(poly); io::WKTWriter *wkt = new io::WKTWriter(); string tmp=wkt->write(pint); cout<<" (WKT coordinateSeq Intersection) "<<tmp<<endl; printf("getNumPoints: %lu\n", pint->getNumPoints()); vector<Geometry *> *newgeoms = new vector<Geometry *>; newgeoms->push_back(pint); cout<<endl<<"----- HERE ARE SOME INTERSECTIONS COMBINATIONS ------"<<endl; wkt_print_geoms(newgeoms); CoordinateSequence *coord = pint->getCoordinates(); printf("Get CoordinateSequence Num: %lu\n", coord->getSize()); for (int i=0; i<coord->getSize(); i++) { printf("Get CoordinateSequence [%d]-(%f, %f)\n", i, coord->getX(i), coord->getY(i)); } delete coord; delete newgeoms; }
void object::test<13>() { Coordinate p1(-123456789, -40); Coordinate p2(381039468754763.0, 123456789); Coordinate q(0, 0); using geos::geom::CoordinateSequence; using geos::geom::GeometryFactory; using geos::geom::LineString; GeometryFactory::Ptr factory = GeometryFactory::create(); CoordinateSequence* cs = new CoordinateArraySequence(); cs->add(p1); cs->add(p2); GeomPtr l ( factory->createLineString(cs) ); GeomPtr p ( factory->createPoint(q) ); ensure(!l->intersects(p.get())); ensure(!CGAlgorithms::isOnLine(q, cs)); ensure_equals(CGAlgorithms::computeOrientation(p1, p2, q), -1); }
void RectangleIntersectionBuilder::reconnect() { // Nothing to reconnect if there aren't at least two lines if(lines.size() < 2) return; geom::LineString * line1 = lines.front(); const geom::CoordinateSequence &cs1 = *line1->getCoordinatesRO(); geom::LineString * line2 = lines.back(); const geom::CoordinateSequence &cs2 = *line2->getCoordinatesRO(); const int n1 = cs1.size(); const int n2 = cs2.size(); // Safety check against bad input to prevent segfaults if(n1==0 || n2==0) return; if (cs1[0] != cs2[n2-1]) return; // Merge the two linestrings CoordinateSequence *ncs = CoordinateSequence::removeRepeatedPoints(&cs2); ncs->add(&cs1, false, true); delete line1; delete line2; LineString * nline = _gf.createLineString(ncs); lines.pop_front(); lines.pop_back(); lines.push_front(nline); }
MultiPoint* WKTReader::readMultiPointText(StringTokenizer *tokenizer) { string nextToken=getNextEmptyOrOpener(tokenizer); if (nextToken=="EMPTY") { return geometryFactory->createMultiPoint(); } int tok = tokenizer->peekNextToken(); if ( tok == StringTokenizer::TT_NUMBER ) { // Try to parse deprecated form "MULTIPOINT(0 0, 1 1)" const CoordinateSequenceFactory* csf = \ geometryFactory->getCoordinateSequenceFactory(); CoordinateSequence *coords = csf->create(NULL); try { do { Coordinate coord; getPreciseCoordinate(tokenizer, coord); coords->add(coord); nextToken=getNextCloserOrComma(tokenizer); } while(nextToken == ","); MultiPoint *ret = geometryFactory->createMultiPoint(*coords); delete coords; return ret; } catch (...) { delete coords; throw; } } else if ( tok == '(' ) { // Try to parse correct form "MULTIPOINT((0 0), (1 1))" vector<Geometry *> *points=new vector<Geometry *>(); try { do { Point *point=readPointText(tokenizer); points->push_back(point); nextToken=getNextCloserOrComma(tokenizer); } while(nextToken == ","); return geometryFactory->createMultiPoint(points); } catch (...) { // clean up for (size_t i=0; i<points->size(); i++) { delete (*points)[i]; } delete points; throw; } } else { stringstream err; err << "Unexpected token: "; switch (tok) { case StringTokenizer::TT_WORD: err << "WORD " << tokenizer->getSVal(); break; case StringTokenizer::TT_NUMBER: err << "NUMBER " << tokenizer->getNVal(); break; case StringTokenizer::TT_EOF: case StringTokenizer::TT_EOL: err << "EOF or EOL"; break; case '(': err << "("; break; case ')': err << ")"; break; case ',': err << ","; break; default: err << "??"; break; } err << endl; throw ParseException(err.str()); return NULL; } }