Example #1
0
void
WKBWriter::write(const Geometry &g, ostream &os) 
{
	outStream = &os;

	switch (g.getGeometryTypeId()) {
		case GEOS_POINT:
			return writePoint((Point &)g);
		case GEOS_LINESTRING:
		case GEOS_LINEARRING:
			return writeLineString((LineString &)g);
		case GEOS_POLYGON:
			return writePolygon((Polygon &)g);
		case GEOS_MULTIPOINT:
			return writeGeometryCollection(
				(GeometryCollection &)g,
				WKBConstants::wkbMultiPoint);
		case GEOS_MULTILINESTRING:
			return writeGeometryCollection(
				(GeometryCollection &)g,
				WKBConstants::wkbMultiLineString);
		case GEOS_MULTIPOLYGON:
			return writeGeometryCollection(
				(GeometryCollection &)g,
				WKBConstants::wkbMultiPolygon);
		case GEOS_GEOMETRYCOLLECTION:
			return writeGeometryCollection(
				(GeometryCollection &)g,
				WKBConstants::wkbGeometryCollection);
		case GEOM_CIRCULARARC:
			return writeCircularArc((CircularArc&)g);
		default:
			assert(0); // Unknown Geometry type
	}
}
Example #2
0
void
WKBWriter::write(const Geometry& g, ostream& os)
{
    outputDimension = defaultOutputDimension;
    if(outputDimension > g.getCoordinateDimension()) {
        outputDimension = g.getCoordinateDimension();
    }

    outStream = &os;

    if(const Point* x = dynamic_cast<const Point*>(&g)) {
        return writePoint(*x);
    }

    if(const LineString* x = dynamic_cast<const LineString*>(&g)) {
        return writeLineString(*x);
    }

    if(const Polygon* x = dynamic_cast<const Polygon*>(&g)) {
        return writePolygon(*x);
    }

    if(const MultiPoint* x = dynamic_cast<const MultiPoint*>(&g)) {
        return writeGeometryCollection(*x, WKBConstants::wkbMultiPoint);
    }

    if(const MultiLineString* x = dynamic_cast<const MultiLineString*>(&g)) {
        return writeGeometryCollection(*x, WKBConstants::wkbMultiLineString);
    }

    if(const MultiPolygon* x = dynamic_cast<const MultiPolygon*>(&g)) {
        return writeGeometryCollection(*x, WKBConstants::wkbMultiPolygon);
    }

    if(const GeometryCollection* x =
                dynamic_cast<const GeometryCollection*>(&g)) {
        return writeGeometryCollection(*x, WKBConstants::wkbGeometryCollection);
    }

    assert(0); // Unknown Geometry type
}
Example #3
0
void BSPFile::write( io::OutputStream* out ) 
{
	Debug::println( "bsp: Writing BSP tree to {0}...", out->toString() );

	// write version
	ChunkOutputStream output( out );
	output.beginChunk( "bsptree" );
	output.writeInt( BSP_FILE_VERSION );

	// write node count
	assert( m_tree->nodes() > 0 );
	output.writeInt( m_tree->nodes() );

	// write total number of polys in all nodes
	output.writeInt( getTreePolygonCount(m_tree->root()) );

	// write vertices
	output.beginChunk( "vertices" );
	int nvertices = m_tree->vertexData.size();
	output.writeInt( nvertices );
	for ( int i = 0 ; i < nvertices ; ++i )
		for ( int k = 0 ; k < 3 ; ++k )
			output.writeFloat( m_tree->vertexData[i][k] );
	output.endChunk();

	// write polygons
	output.beginChunk( "polygons" );
	output.writeInt( m_tree->polygons() );
	for ( int i = 0 ; i < m_tree->polygons() ; ++i )
		writePolygon( &output, m_tree->getPolygon(i) );
	output.endChunk();

	// write node tree
	writeNode( &output, m_tree->root() );

	output.endChunk();
}