コード例 #1
0
ファイル: example.cpp プロジェクト: border/notes
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;
}
コード例 #2
0
ファイル: LineMergeGraph.cpp プロジェクト: asapnet/geos
void
LineMergeGraph::addEdge(const LineString *lineString)
{
	if (lineString->isEmpty()) return;

#if GEOS_DEBUG
	cerr<<"Adding LineString "<<lineString->toString()<<endl;
#endif

	CoordinateSequence *coordinates = 
		CoordinateSequence::removeRepeatedPoints(lineString->getCoordinatesRO());

	const Coordinate& startCoordinate=coordinates->getAt(0);
	const Coordinate& endCoordinate=coordinates->getAt(coordinates->getSize()-1);

	planargraph::Node* startNode=getNode(startCoordinate);
	planargraph::Node* endNode=getNode(endCoordinate);
#if GEOS_DEBUG
	cerr<<" startNode: "<<*startNode<<endl;
	cerr<<" endNode: "<<*endNode<<endl;
#endif

	planargraph::DirectedEdge *directedEdge0=new LineMergeDirectedEdge(startNode,
			endNode,coordinates->getAt(1),
			true);
	newDirEdges.push_back(directedEdge0);

	planargraph::DirectedEdge *directedEdge1=new LineMergeDirectedEdge(endNode,
			startNode,coordinates->getAt(coordinates->getSize()-2),
			false);
	newDirEdges.push_back(directedEdge1);

	planargraph::Edge *edge=new LineMergeEdge(lineString);
	newEdges.push_back(edge);
	edge->setDirectedEdges(directedEdge0, directedEdge1);

#if GEOS_DEBUG
	cerr<<" planargraph::Edge: "<<*edge<<endl;
#endif

	add(edge);

#if GEOS_DEBUG
	cerr<<" After addition to the graph:"<<endl;
	cerr<<"  startNode: "<<*startNode<<endl;
	cerr<<"  endNode: "<<*endNode<<endl;
#endif

	delete coordinates;
}
コード例 #3
0
ファイル: WKTWriter.cpp プロジェクト: asapnet/geos
/*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();
}
コード例 #4
0
ファイル: example.cpp プロジェクト: border/notes
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;
}
コード例 #5
0
ファイル: WKBWriter.cpp プロジェクト: lozpeng/applesales
void
WKBWriter::writeCoordinateSequence(const CoordinateSequence &cs,
	bool sized) 
{
	int size = cs.getSize();
	bool is3d=false;
	if ( cs.getDimension() > 2 && outputDimension > 2) is3d = true;

	if (sized) writeInt(size);
	for (int i=0; i<size; i++) writeCoordinate(cs, i, is3d);
}
コード例 #6
0
ファイル: WKBWriter.cpp プロジェクト: libgeos/libgeos
void
WKBWriter::writeCoordinateSequence(const CoordinateSequence& cs,
                                   bool sized)
{
    std::size_t size = cs.getSize();
    bool is3d = false;
    if(outputDimension > 2) {
        is3d = true;
    }

    if(sized) {
        writeInt(static_cast<int>(size));
    }
    for(std::size_t i = 0; i < size; i++) {
        writeCoordinate(cs, i, is3d);
    }
}
コード例 #7
0
void VectorLayerEditor::_init()
{
    if(_inited)
        return;

    // Load geometry
    AmigoApplicationData &appData = AmigoApplication::instance().getData();
    if(auto project = appData.getUser().projects.findProject(_editorParams.projectId))
    {
        std::vector<std::string> wkbOut;
        std::shared_ptr<APIv1::Dataset> ds = std::dynamic_pointer_cast<APIv1::Dataset>(project->datasets.findDataset(_editorParams.datasetId));
        if(ds)
        {
            if(_editorParams.savedWkb.empty())
            {
                project->db.geoQueryWKB(ds->table_name, _editorParams.jsonRecord, wkbOut, ds->online_only);
                AMIGO_LOG_I(TAG, "::_init() wkbOut.size()=%d\n", wkbOut.size());
            }
            else
            {
                AMIGO_LOG_I(TAG, "::_init() restore '%s'\n", _editorParams.savedWkb.c_str());
                _geometry = GeometryHandler::parseWKBHex(_editorParams.savedWkb);
            }

            if(_geometry == NULL)
            {
                if(wkbOut.size()==1 && wkbOut[0].size()>0)
                {
                    AMIGO_LOG_I(TAG, "::_init() '%s'\n", wkbOut[0].c_str());
                    _geometry = GeometryHandler::parseWKBHex(wkbOut[0]);
                } else {
                    // There is no geometry
                    _createEmptyGeometry();
                }
            }

            if(_geometry!=NULL)
            {
                GeometryTypeId gtype = _geometry->getGeometryTypeId();
                int type;
                switch (gtype) {
                case GEOS_POINT:
                    type = ShapeEditor::T_POINT;
                    break;

                case GEOS_LINESTRING:
                    type = ShapeEditor::T_LINE;
                    break;

                case GEOS_LINEARRING:
                    type = ShapeEditor::T_LINE;
                    break;

                case GEOS_POLYGON:
                    type = ShapeEditor::T_POLYGON;
                    break;

                case GEOS_MULTIPOINT:
                    type = ShapeEditor::T_POINTS;
                    break;

                case GEOS_MULTILINESTRING:
                    type = ShapeEditor::T_LINES;
                    break;

                case GEOS_MULTIPOLYGON:
                    type = ShapeEditor::T_POLYGONS;
                    break;

                case GEOS_GEOMETRYCOLLECTION:
                    type = ShapeEditor::T_POINTS;
                    break;

                default:
                    type = ShapeEditor::T_POINTS;
                    break;
                };
                AMIGO_LOG_I(TAG, "::_init() type=%d, gtype=%d\n", type, gtype);
                _coords.clear();
                for(size_t g = 0; g < _geometry->getNumGeometries(); g++)
                {
                    PointList pList;
                    CoordinateSequence *cs = _geometry->getGeometryN(g)->getCoordinates();
                    // Remove closing point in polygons
                    unsigned size = cs->getSize() - ((type == ShapeEditor::T_POLYGONS || type == ShapeEditor::T_POLYGON)? 1 : 0);
                    for(unsigned i=0; i < size; i++ )
                    {
                        Coordinate c;
                        cs->getAt(i, c);
                        double alt = Globe::instance()->getGlobeSceneHandler()->getElevationAt( c.y, c.x);
                        pList.push_back( iiMath::vec3(c.y, c.x, alt) );
                    }
                    _coords.push_back(pList);
                    delete cs;
                }
                _shapeEditor.load(type, _coords);
            }
        }
        else
        {
            AMIGO_LOG_E(TAG, "::_init() dataset not found: %lu\n", _editorParams.datasetId);
        }
    } else
    {
        AMIGO_LOG_E(TAG, "::_init() project not found: %lu\n", _editorParams.projectId);

    }
    _shapeEditor.setState(GeometryEditorListener::NO_SELECTION);

    _labelStateSet = std::make_shared<LabelVectorStateSet>(false);
    _labelDrawSet = std::make_shared<DrawSetT>();
    _labelDrawSet->setStateSet(_labelStateSet);

    _inited=true;
}