コード例 #1
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;
}
コード例 #2
0
ファイル: WayAverager.cpp プロジェクト: andyneff/hootenanny
Coordinate WayAverager::_moveToLineAsCoordinate(long ni, double nWeight, const LineString* ls,
                                                double lWeight)
{
  shared_ptr<Node> n = _map.getNode(ni);
  Point* point(GeometryFactory::getDefaultInstance()->createPoint(n->toCoordinate()));

  // find the two closest points
  CoordinateSequence* cs = DistanceOp::closestPoints(point, const_cast<LineString*>(ls));

  Coordinate result = Coordinate(cs->getAt(0).x * nWeight + cs->getAt(1).x * lWeight,
                                 cs->getAt(0).y * nWeight + cs->getAt(1).y * lWeight);

  delete cs;
  delete point;

  return result;
}
コード例 #3
0
CoordinateArraySequence::CoordinateArraySequence(
    const CoordinateSequence &c )
	:
	CoordinateSequence(c),
	vect(new vector<Coordinate>(c.size())),
  dimension(c.getDimension())
{
  for (size_t i = 0, n = vect->size(); i < n; ++i) {
      (*vect)[i] = c.getAt(i);
  }
}
コード例 #4
0
ファイル: BaseComparator.cpp プロジェクト: giserh/hootenanny
Coordinate BaseComparator::_findNearestPointOnFeature(shared_ptr<OsmMap> map, Coordinate c)
{
  Coordinate result;

  // find the nearest feature
  long wId = map->getIndex().findNearestWay(c);
  shared_ptr<Way> w = map->getWay(wId);

  // find the nearest point on that feature.
  shared_ptr<Point> p(GeometryFactory::getDefaultInstance()->createPoint(c));
  shared_ptr<LineString> ls = ElementConverter(map).convertToLineString(w);
  CoordinateSequence* cs = DistanceOp::closestPoints(p.get(), ls.get());

  cs->getAt(0, result);

  delete cs;

  return result;
}
コード例 #5
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;
}