Esempio n. 1
0
/*static*/
string
WKTWriter::toLineString(const CoordinateSequence& seq)
{
	stringstream buf("LINESTRING ", ios_base::in|ios_base::out);
	unsigned int npts = seq.getSize();
	if ( npts == 0 )
	{
		buf << "EMPTY";
	}
	else
	{
		buf << "(";
		for (unsigned int i=0; i<npts; ++i)
		{
			if (i) buf << ", ";
			buf << seq.getX(i) << " " << seq.getY(i);
#if PRINT_Z
			buf << seq.getZ(i);
#endif
		}
		buf << ")";
	}

	return buf.str();
}
Esempio n. 2
0
void
WKBWriter::writeCoordinate(const CoordinateSequence& cs, size_t idx,
                           bool is3d)
{
#if DEBUG_WKB_WRITER
    cout << "writeCoordinate: X:" << cs.getX(idx) << " Y:" << cs.getY(idx) << endl;
#endif
    assert(outStream);

    ByteOrderValues::putDouble(cs.getX(idx), buf, byteOrder);
    outStream->write(reinterpret_cast<char*>(buf), 8);
    ByteOrderValues::putDouble(cs.getY(idx), buf, byteOrder);
    outStream->write(reinterpret_cast<char*>(buf), 8);
    if(is3d) {
        ByteOrderValues::putDouble(
            cs.getOrdinate(idx, CoordinateSequence::Z),
            buf, byteOrder);
        outStream->write(reinterpret_cast<char*>(buf), 8);
    }
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
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;
}