Beispiel #1
0
void ForceValidityVisitor::visit( MultiPolygon& g )
{
    g.forceValidityFlag( valid_ );
    for ( size_t i = 0; i < g.numGeometries(); i++ ) {
        visit( g.polygonN( i ) );
    }
}
Beispiel #2
0
	std::auto_ptr<Geometry> collect( const Geometry& ga, const Geometry& gb )
	{
		if ( ga.geometryTypeId() == gb.geometryTypeId() ) {
			if ( ga.geometryTypeId() == TYPE_POINT ) {
				MultiPoint *mp = new MultiPoint;
				mp->addGeometry( ga );
				mp->addGeometry( gb );
				return std::auto_ptr<Geometry>(mp);
			}
			else if ( ga.geometryTypeId() == TYPE_LINESTRING ) {
				MultiLineString *mls = new MultiLineString();
				mls->addGeometry(ga);
				mls->addGeometry(gb);
				return std::auto_ptr<Geometry>( mls );
			}
			else if ( ga.geometryTypeId() == TYPE_POLYGON ) {
				MultiPolygon *mp = new MultiPolygon();
				mp->addGeometry(ga);
				mp->addGeometry(gb);
				return std::auto_ptr<Geometry>( mp );
			}
			else if ( ga.geometryTypeId() == TYPE_SOLID ) {
				MultiSolid *mp = new MultiSolid();
				mp->addGeometry(ga);
				mp->addGeometry(gb);
				return std::auto_ptr<Geometry>( mp );
			}
		}

		// else
		GeometryCollection* coll = new GeometryCollection();
		coll->addGeometry(ga);
		coll->addGeometry(gb);
		return std::auto_ptr<Geometry>( coll );
	}
mapnik::geometry::multi_polygon<double>  geowave_featureset::create_multi_polygon(MultiPolygon multi_polygon)
{
    mapnik::geometry::multi_polygon<double> multi_polygon_out;
    for (int geom_idx = 0; geom_idx < multi_polygon.getNumGeometries(); ++geom_idx)
        multi_polygon_out.push_back(create_polygon(java_cast<Polygon>(multi_polygon.getGeometryN(geom_idx))));
    return multi_polygon_out;
}
Beispiel #4
0
QList<ControlPoint *> getValidPoints(Cube &cube, STRtree &coordTree) {
  ImagePolygon poly;
  try {
    cube.read(poly);
  }
  catch (IException &e) {
    QString msg = "Footprintinit must be run prior to running cnetadd";
    msg += " with POLYGON=TRUE for cube [" + cube.fileName() + "]";
    throw IException(e, IException::User, msg, _FILEINFO_);
  }

  std::vector<void *> matches;
  MultiPolygon *polys = poly.Polys();
  for (unsigned int i = 0; i < polys->getNumGeometries(); i++) {
    const Geometry *geometry = polys->getGeometryN(i);
    const Envelope *boundingBox = geometry->getEnvelopeInternal();

    coordTree.query(boundingBox, matches);
  }

  QList<ControlPoint *> results;
  for (unsigned int i = 0; i < matches.size(); i++) {
    results.append((ControlPoint *) matches[i]);
  }

  return results;
}
Handle<Value> MultiPolygon::New(const Arguments& args)
{
	HandleScope scope;
	MultiPolygon *f;

	if (!args.IsConstructCall()) {
		return NODE_THROW("Cannot call constructor as function, you need to use 'new' keyword");
	}

	if (args[0]->IsExternal()) {
		Local<External> ext = Local<External>::Cast(args[0]);
		void* ptr = ext->Value();
		f = static_cast<MultiPolygon *>(ptr);

	} else {
		if (args.Length() != 0) {
			return NODE_THROW("MultiPolygon constructor doesn't take any arguments");
		}
		f = new MultiPolygon(new OGRMultiPolygon());
	}

	Handle<Value> children = GeometryCollectionChildren::New(args.This()); 
	args.This()->SetHiddenValue(String::NewSymbol("children_"), children); 

	f->Wrap(args.This());
	return args.This();
}
Beispiel #6
0
std::auto_ptr< MultiLineString > straightSkeleton( const MultiPolygon& g )
{
	std::auto_ptr< MultiLineString > result( new MultiLineString );
	for ( size_t i = 0; i < g.numGeometries(); i++ ){
		Polygon_with_holes_2 polygon = g.polygonN(i).toPolygon_with_holes_2() ;
		boost::shared_ptr< Straight_skeleton_2 > skeleton = CGAL::create_interior_straight_skeleton_2( polygon ) ;
		straightSkeletonToMultiLineString( *skeleton, *result ) ;
	}
	return result ;
}
Beispiel #7
0
void BoundaryVisitor::visit( const MultiPolygon& g )
{
    graph::GeometryGraph        graph ;
    graph::GeometryGraphBuilder graphBuilder( graph ) ;

    for ( size_t i = 0; i < g.numGeometries(); i++ ) {
        graphBuilder.addPolygon( g.polygonN( i ) );
    }

    getBoundaryFromPolygons( graph ) ;
}
Beispiel #8
0
 static inline void apply(MultiPolygon const& mp, Box& mbr)
 {
     assign_inverse(mbr);
     for (typename boost::range_const_iterator<MultiPolygon>::type
                 it = mp.begin();
         it != mp.end();
         ++it)
     {
         envelope_range_additional(exterior_ring(*it), mbr);
     }
 }
Beispiel #9
0
std::auto_ptr< Geometry > building(
    const MultiPolygon& g,
    const Kernel::FT& wallHeight,
    const Kernel::FT& roofSlope
)
{
    std::auto_ptr< MultiSolid > multiSolid( new MultiSolid );

    for ( size_t i = 0; i < g.numGeometries(); i++ ) {
        multiSolid->addGeometry( building( g.polygonN( i ), wallHeight, roofSlope ).release() );
    }

    return std::auto_ptr< Geometry >( multiSolid.release() );
}
Beispiel #10
0
inline void make_polygon(MultiPolygon& mp, int count_x, int count_y, int index, int width_x)
{
    typedef typename bg::point_type<MultiPolygon>::type point_type;

    for(int j = 0; j < count_x; ++j)
    {
        for(int k = 0; k < count_y; ++k)
        {
            mp.push_back(MultiPolygon::value_type());
            mp.back().outer().push_back(point_type(width_x + j * 10 + 1, k * 10 + 1));
            mp.back().outer().push_back(point_type(width_x + j * 10 + width_x, k * 10 + 5 + index));
            mp.back().outer().push_back(point_type(width_x + j * 10 + 5 + index, k * 10 + 7));
            mp.back().outer().push_back(point_type(width_x + j * 10 + 1, k * 10 + 1));
        }
    }
}
void WktWriter::write( const MultiPolygon & g )
{
	_s << "MULTIPOLYGON" ;
	if ( g.isEmpty() ){
		_s << " EMPTY" ;
		return ;
	}

	_s << "(";
	for ( size_t i = 0; i < g.numGeometries(); i++ ){
		if ( i != 0 )
			_s << "," ;
		writeInner( g.geometryN(i).as< Polygon >() );
	}
	_s << ")";
}
inline void holify_multi(MultiPolygon& multi_polygon)
{
    typedef typename bg::point_type<MultiPolygon>::type point_type;

    typename boost::range_value<MultiPolygon>::type p;

    bg::exterior_ring(p).push_back(bg::make<point_type>(0, 0));
    bg::exterior_ring(p).push_back(bg::make<point_type>(0, 5000));
    bg::exterior_ring(p).push_back(bg::make<point_type>(5000, 5000));
    bg::exterior_ring(p).push_back(bg::make<point_type>(5000, 0));
    bg::exterior_ring(p).push_back(bg::make<point_type>(0, 0));

    for (int i = 0; i < multi_polygon.size(); i++)
    {
        bg::interior_rings(p).push_back(bg::exterior_ring(multi_polygon[i]));
    }

    bg::correct(p);

    multi_polygon.clear();
    multi_polygon.push_back(p);
}
Beispiel #13
0
void GetPointsVisitor::visit( const MultiPolygon& g )
{
    for ( size_t i = 0; i < g.numGeometries(); i++ ) {
        visit( g.polygonN( i ) );
    }
}
static Feature::geometry_type convertGeometry(const GeometryTileFeature& geometryTileFeature, const CanonicalTileID& tileID) {
    const double size = util::EXTENT * std::pow(2, tileID.z);
    const double x0 = util::EXTENT * tileID.x;
    const double y0 = util::EXTENT * tileID.y;

    auto tileCoordinatesToLatLng = [&] (const Point<int16_t>& p) {
        double y2 = 180 - (p.y + y0) * 360 / size;
        return Point<double>(
            (p.x + x0) * 360 / size - 180,
            360.0 / M_PI * std::atan(std::exp(y2 * M_PI / 180)) - 90.0
        );
    };

    GeometryCollection geometries = geometryTileFeature.getGeometries();

    switch (geometryTileFeature.getType()) {
        case FeatureType::Unknown: {
            assert(false);
            return Point<double>(NAN, NAN);
        }

        case FeatureType::Point: {
            MultiPoint<double> multiPoint;
            for (const auto& p : geometries.at(0)) {
                multiPoint.push_back(tileCoordinatesToLatLng(p));
            }
            if (multiPoint.size() == 1) {
                return multiPoint[0];
            } else {
                return multiPoint;
            }
        }

        case FeatureType::LineString: {
            MultiLineString<double> multiLineString;
            for (const auto& g : geometries) {
                LineString<double> lineString;
                for (const auto& p : g) {
                    lineString.push_back(tileCoordinatesToLatLng(p));
                }
                multiLineString.push_back(std::move(lineString));
            }
            if (multiLineString.size() == 1) {
                return multiLineString[0];
            } else {
                return multiLineString;
            }
        }

        case FeatureType::Polygon: {
            MultiPolygon<double> multiPolygon;
            for (const auto& pg : classifyRings(geometries)) {
                Polygon<double> polygon;
                for (const auto& r : pg) {
                    LinearRing<double> linearRing;
                    for (const auto& p : r) {
                        linearRing.push_back(tileCoordinatesToLatLng(p));
                    }
                    polygon.push_back(std::move(linearRing));
                }
                multiPolygon.push_back(std::move(polygon));
            }
            if (multiPolygon.size() == 1) {
                return multiPolygon[0];
            } else {
                return multiPolygon;
            }
        }
    }

    // Unreachable, but placate GCC.
    return Point<double>();
}