Buildings from shapefile

classic Classic list List threaded Threaded
13 messages Options
ElRudi ElRudi
Reply | Threaded
Open this post in threaded view
|

Buildings from shapefile

Hi,

i want to show buildings from shapefile like in the osgearth_city example or in the boston earth file. I downloaded OpenStreetMap building data from http://download.geofabrik.de/ and replaced the filename in the sourcecode with the new one, but there are no buildings in the scene. Where can i find information on how to use this feature? Have i to prepare the shape files somehow? One difference to your example shape file ist, that you are using UTM coordinates instead of Lat/Long. Is this needed?

Cheers
ElRudi
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

ElRudi,

I am familiar with Geofabrik but haven't looked at their shapefiles in a long time.  I would look at the simplest example, feature_extrude.earth.

You can also set OSGEARTH_NOTIFY_LEVEL=INFO when running feature_extrude.earth with your shapefile and that might point to the problem

If that does not work, point me to the shapefile you are using and I can take a quick look.

--
Paul Levy : Pelican Mapping


On Wed, May 6, 2020 at 6:30 AM ElRudi [via osgEarth] <[hidden email]> wrote:
Hi,

i want to show buildings from shapefile like in the osgearth_city example or in the boston earth file. I downloaded OpenStreetMap building data from http://download.geofabrik.de/ and replaced the filename in the sourcecode with the new one, but there are no buildings in the scene. Where can i find information on how to use this feature? Have i to prepare the shape files somehow? One difference to your example shape file ist, that you are using UTM coordinates instead of Lat/Long. Is this needed?

Cheers
ElRudi


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Buildings-from-shapefile-tp7593153.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
ElRudi ElRudi
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

feature_extrude.earth is working with my shape file, but boston.earth is not. I simplified the boston earth file:

<map name="Boston Demo" type="geocentric" version="2">
    <image name="readymap_imagery" driver="tms">
        <url>http://readymap.org/readymap/tiles/1.0.0/22/</url>
    </image>
   
    <elevation name="readymap_elevation" driver="tms">
        <url>http://readymap.org/readymap/tiles/1.0.0/116/</url>
    </elevation>
     
    <feature_model name="buildings">
         
        <features name="buildings" driver="ogr">

            <url>../data/ShapeFiles/test.shp</url>
                        <resample min_length="2.5"/>
        </features>
               
        <layout tile_size="500">
            <level name="default" max_range="20000" style="buildings"/>
        </layout>
       
        <styles>           
            <style type="text/css"> buildings { extrusion-height: 100; extrusion-flatten: true; fill: #ff7f2f; stroke: #cf5f00; altitude-clamping: terrain; } </style>        </styles>   
    </feature_model>
</map>


The Output with the original shape and my one is quite the same. the only difference ist the LOD=0 in the
FeatureModelGraph line (original  is LOD=3):

void StateSet::setGlobalDefaults() ShaderPipeline disabled.
[osgEarth]  [EarthSerializer2] Loaded extension lib "osgPlugins-3.7.0/osgdb_osgearth_viewpoints.dll"
[osgEarth]  [Map] cache=none; policy=read-write; bin=no
[osgEarth]  [TerrainLayer] Layer "readymap_elevation" Creating "tms" driver
[osgEarth]  [TMSTileSource] TMS tile map datestamp = Thu, 01 Jan 1970 00:00:00 GMT
[osgEarth]  [TerrainLayer] Layer "readymap_elevation" Profile=[srs=WGS 84, min=-180,-90 max=180,90 lod0=2,1 vdatum=geodetic]
[osgEarth]  [TerrainLayer] Layer "readymap_elevation" cache=none; policy=read-write; bin=no
[osgEarth]  [TerrainLayer] Layer "readymap_imagery" Creating "tms" driver
[osgEarth]  [TMSTileSource] TMS tile map datestamp = Thu, 01 Jan 1970 00:00:00 GMT
[osgEarth]  [TerrainLayer] Layer "readymap_imagery" Profile=[srs=WGS 84, min=-180,-90 max=180,90 lod0=2,1 vdatum=geodetic]
[osgEarth]  [TerrainLayer] Layer "readymap_imagery" cache=none; policy=read-write; bin=no
[osgEarth]  [FeatureModelLayer] Setting feature source "buildings"
[osgEarth]  [Map] Map profile is: [srs=WGS 84, min=-180,-90 max=180,90 lod0=2,1 vdatum=geodetic]
[osgEarth]  [FeatureModelGraph] osgEarth.FeatureModelGraph: tileSize = 500; maxRange = 20000; tsf=40
[osgEarth]  [FeatureModelGraph] osgEarth.FeatureModelGraph: buildings: F.Level max=20000, min=0, LOD=0
[osgEarth]  [ViewpointsExtension] Read 4 viewpoints
[osgEarth]  [engine_rex] Activated!
[osgEarth]  [Capabilities] osgEarth Version: 2.10.2
[osgEarth]  [Capabilities] OSG Version:      3.7.0
[osgEarth]  [Capabilities] GDAL Version:     2.1.3
[osgEarth]  [Capabilities] Detected hardware capabilities:
[osgEarth]  [Capabilities]   Vendor = Intel
[osgEarth]  [Capabilities]   Renderer = Intel(R) UHD Graphics 630
[osgEarth]  [Capabilities]   Version = 4.5.0 - Build 23.20.16.5037
[osgEarth]  [Capabilities]   Core Profile = no
[osgEarth]  [Capabilities]   Max GPU texture units = 32
[osgEarth]  [Capabilities]   Max GPU texture coord indices = 8
[osgEarth]  [Capabilities]   Max GPU attributes = 16
[osgEarth]  [Capabilities]   Depth buffer bits = 24
[osgEarth]  [Capabilities]   Max texture size = 16384
[osgEarth]  [Capabilities]   GLSL = yes
[osgEarth]  [Capabilities]   GLSL Version = 450
[osgEarth]  [Capabilities]   Texture arrays = yes
[osgEarth]  [Capabilities]   draw instanced = yes
[osgEarth]  [Capabilities]   Texture buffers = yes
[osgEarth]  [Capabilities]   Texture buffer max size = 134217728
[osgEarth]  [Capabilities]   Compression = ARB S3
[osgEarth]  [PagerLoader] Merges per frame = 20
[osgEarth]  [TerrainResources] Texture unit 0 reserved for Terrain Color
[osgEarth]  [TerrainResources] Texture unit 1 reserved for Terrain Elevation
[osgEarth]  [TerrainResources] Texture unit 2 reserved for Terrain Normals
[osgEarth]  [TerrainResources] Texture unit 3 reserved for Terrain Parent Color
Now checking for plug-in osgPlugins-3.7.0/osgdb_nvtt.dll
osg::Registry::addImageProcessor(ImageProcessor)
Loaded plug-in osgPlugins-3.7.0/osgdb_nvtt.dll and located ImageProcessor
void StateSet::setGlobalDefaults() ShaderPipeline disabled.
[osgEarth]  [SelectionInfo] LOD Ranges:
[osgEarth]  [MapNode] Added extension "viewpoints"
[osgEarth]* CropFilter - METHOD_CROPPING not available - please compile osgEarth with GEOS
osg::Registry::removeImageProcessor();

I downloaded the file http://download.geofabrik.de/europe/germany/bremen-latest-free.shp.zip and cropped the building shape file with QGIS.
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

I am not exactly sure what is happening with the resample filter on that file but try removing it and adding the spatial_index.  Here is my .earth file which is 3.0 syntax so won't directly run in 2.10


<map name="Boston Demo" type="geocentric" version="2">
   
    <TMSImage name="Imagery">
        <url>http://readymap.org/readymap/tiles/1.0.0/22/</url>
    </TMSImage>
   
    <xi:include href="readymap_elevation.xml"/>
     
    <FeatureModel name="buildings">
         
        <OGRFeatures name="buildings" driver="ogr">
            <url>M:\bremmer\gis_osm_buildings_a_free_1.shp</url>
<build_spatial_index>true</build_spatial_index>
        </OGRFeatures>
               
        <layout tile_size="500">
            <level name="default" max_range="200000" style="buildings"/>
        </layout>
       
        <styles>            
            <library name="us_resources">
                <url>../data/resources/textures_us/catalog.xml</url>
            </library>
           
            <style type="text/css">
                buildings {
                    extrusion-height:       30;
                    extrusion-flatten:       true;
                    extrusion-wall-style:    building-wall;
                    extrusion-wall-gradient: 0.5;
                    extrusion-roof-style:    building-rooftop;
                    altitude-clamping:       terrain;
                    altitude-technique:      map;
                    altitude-binding:        vertex;
altitude-resolution:     0;
                }            
                building-wall {
                    skin-library:     us_resources;
                    skin-tags:        building;
                    skin-random-seed: 1;
                }
                building-rooftop {
                    skin-library:     us_resources;
                    skin-tags:        rooftop;
                    skin-tiled:       true;
                    skin-random-seed: 1;
                }
            </style>
        </styles>  
    </FeatureModel>

<viewpoints>
<viewpoint>
 <heading>-6.44977</heading>
 <pitch>-19.2184</pitch>
 <range>16799.1m</range>
 <long>8.584042520441608</long>
 <lat>53.54276020770987</lat>
 <height>42.99006401747465</height>
 <srs>+proj=longlat +datum=WGS84 +no_defs </srs>
</viewpoint>
    </viewpoints>
 
 
 
</map>



On Thu, May 7, 2020 at 11:20 AM ElRudi [via osgEarth] <[hidden email]> wrote:
feature_extrude.earth is working with my shape file, but boston.earth is not. I simplified the boston earth file:

<map name="Boston Demo" type="geocentric" version="2">
    <image name="readymap_imagery" driver="tms">
        <url>http://readymap.org/readymap/tiles/1.0.0/22/</url>
    </image>
   
    <elevation name="readymap_elevation" driver="tms">
        <url>http://readymap.org/readymap/tiles/1.0.0/116/</url>
    </elevation>
     
    <feature_model name="buildings">
         
        <features name="buildings" driver="ogr">

            <url>../data/ShapeFiles/test.shp</url>
                        <resample min_length="2.5"/>
        </features>
               
        <layout tile_size="500">
            <level name="default" max_range="20000" style="buildings"/>
        </layout>
       
        <styles>           
            <style type="text/css"> buildings { extrusion-height: 100; extrusion-flatten: true; fill: #ff7f2f; stroke: #cf5f00; altitude-clamping: terrain; } </style>        </styles>   
    </feature_model>
</map>


The Output with the original shape and my one is quite the same. the only difference ist the LOD=0 in the
FeatureModelGraph line (original  is LOD=3):

void StateSet::setGlobalDefaults() ShaderPipeline disabled.
[osgEarth]  [EarthSerializer2] Loaded extension lib "osgPlugins-3.7.0/osgdb_osgearth_viewpoints.dll"
[osgEarth]  [Map] cache=none; policy=read-write; bin=no
[osgEarth]  [TerrainLayer] Layer "readymap_elevation" Creating "tms" driver
[osgEarth]  [TMSTileSource] TMS tile map datestamp = Thu, 01 Jan 1970 00:00:00 GMT
[osgEarth]  [TerrainLayer] Layer "readymap_elevation" Profile=[srs=WGS 84, min=-180,-90 max=180,90 lod0=2,1 vdatum=geodetic]
[osgEarth]  [TerrainLayer] Layer "readymap_elevation" cache=none; policy=read-write; bin=no
[osgEarth]  [TerrainLayer] Layer "readymap_imagery" Creating "tms" driver
[osgEarth]  [TMSTileSource] TMS tile map datestamp = Thu, 01 Jan 1970 00:00:00 GMT
[osgEarth]  [TerrainLayer] Layer "readymap_imagery" Profile=[srs=WGS 84, min=-180,-90 max=180,90 lod0=2,1 vdatum=geodetic]
[osgEarth]  [TerrainLayer] Layer "readymap_imagery" cache=none; policy=read-write; bin=no
[osgEarth]  [FeatureModelLayer] Setting feature source "buildings"
[osgEarth]  [Map] Map profile is: [srs=WGS 84, min=-180,-90 max=180,90 lod0=2,1 vdatum=geodetic]
[osgEarth]  [FeatureModelGraph] osgEarth.FeatureModelGraph: tileSize = 500; maxRange = 20000; tsf=40
[osgEarth]  [FeatureModelGraph] osgEarth.FeatureModelGraph: buildings: F.Level max=20000, min=0, LOD=0
[osgEarth]  [ViewpointsExtension] Read 4 viewpoints
[osgEarth]  [engine_rex] Activated!
[osgEarth]  [Capabilities] osgEarth Version: 2.10.2
[osgEarth]  [Capabilities] OSG Version:      3.7.0
[osgEarth]  [Capabilities] GDAL Version:     2.1.3
[osgEarth]  [Capabilities] Detected hardware capabilities:
[osgEarth]  [Capabilities]   Vendor = Intel
[osgEarth]  [Capabilities]   Renderer = Intel(R) UHD Graphics 630
[osgEarth]  [Capabilities]   Version = 4.5.0 - Build 23.20.16.5037
[osgEarth]  [Capabilities]   Core Profile = no
[osgEarth]  [Capabilities]   Max GPU texture units = 32
[osgEarth]  [Capabilities]   Max GPU texture coord indices = 8
[osgEarth]  [Capabilities]   Max GPU attributes = 16
[osgEarth]  [Capabilities]   Depth buffer bits = 24
[osgEarth]  [Capabilities]   Max texture size = 16384
[osgEarth]  [Capabilities]   GLSL = yes
[osgEarth]  [Capabilities]   GLSL Version = 450
[osgEarth]  [Capabilities]   Texture arrays = yes
[osgEarth]  [Capabilities]   draw instanced = yes
[osgEarth]  [Capabilities]   Texture buffers = yes
[osgEarth]  [Capabilities]   Texture buffer max size = 134217728
[osgEarth]  [Capabilities]   Compression = ARB S3
[osgEarth]  [PagerLoader] Merges per frame = 20
[osgEarth]  [TerrainResources] Texture unit 0 reserved for Terrain Color
[osgEarth]  [TerrainResources] Texture unit 1 reserved for Terrain Elevation
[osgEarth]  [TerrainResources] Texture unit 2 reserved for Terrain Normals
[osgEarth]  [TerrainResources] Texture unit 3 reserved for Terrain Parent Color
Now checking for plug-in osgPlugins-3.7.0/osgdb_nvtt.dll
osg::Registry::addImageProcessor(ImageProcessor)
Loaded plug-in osgPlugins-3.7.0/osgdb_nvtt.dll and located ImageProcessor
void StateSet::setGlobalDefaults() ShaderPipeline disabled.
[osgEarth]  [SelectionInfo] LOD Ranges:
[osgEarth]  [MapNode] Added extension "viewpoints"
[osgEarth]* CropFilter - METHOD_CROPPING not available - please compile osgEarth with GEOS
osg::Registry::removeImageProcessor();

I downloaded the shape file http://download.geofabrik.de/europe/germany/bremen-latest-free.shp.zip and cropped it with QGIS.


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Buildings-from-shapefile-tp7593153p7593157.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
ElRudi ElRudi
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

This post was updated on .
Ok, now it works with constant extrusion-height, but the height of the buildings is not included in the free data from Geofabrik.

Do you know a good solution to export shape files of buildings from OSM Data with height included?

I have a GeoJson file which items look like this:

      {
         "geometry":
         {
            "coordinates":
            [
               
               [
                 
                  [
                     -5.9359495,
                     54.5824276,
                     4
                  ],
                 
                  [
                     -5.9357371,
                     54.5824563,
                     4
                  ],
                                 
                  [
                     -5.9348788,
                     54.5825724,
                     4
                  ],
                                   
                  [
                     -5.9359495,
                     54.5824276,
                     4
                  ]
               ]
            ],
            "properties":
            {
               "height":4
            },
            "type":"Polygon"
         },
         "type":"Feature"
      }

How can i define the height in properties as extrusion-height?
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

I do not think the geofabrik extracts maintain all the attributes so you may need to do your own extraction and examine the data for height attributes such as "height" or "levels".  I would look at the data on openstreetmap.org and see if any height data is available.

--
Paul Levy : Pelican Mapping


On Fri, May 8, 2020 at 6:07 AM ElRudi [via osgEarth] <[hidden email]> wrote:
Ok, now it works with constant extrusion-height, but the attribute "story_ht_" is not defined in the data from Geofabrik. So where can i find the height of the buildings?


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Buildings-from-shapefile-tp7593153p7593159.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
ElRudi ElRudi
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

Ok. One solution i have is the geojson export. But how can i define the extrusion-height in this case? The height of the buildings in this export is defined in the altitude of the coordinates and in the properties attribute as in the example above.
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

Without seeing the data, two options come to mind.  Convert your geojson data to shapefiles which would be similar to the existing example but you would need to determine which attributes contain the height value.  Use ogr2ogr or QGIS.  Using the geojson might be similar to the openstreetmap_full.test which has a function getBuildingHeight()  where you can use javascript to find the height data from a few different attributes.

Using QGIS to explore the data might be useful to determine which attributes are needed and exporting into shapefiles.
 
--
Paul Levy : Pelican Mapping


On Sat, May 9, 2020 at 8:42 AM ElRudi [via osgEarth] <[hidden email]> wrote:
Ok. One solution i have is the geojson export. But how can i define the extrusion-height in this case? The height of the buildings in this export is defined in the altitude of the coordinates and in the properties attribute as in the example above.


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Buildings-from-shapefile-tp7593153p7593161.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
ElRudi ElRudi
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

This post was updated on .
Thank you for the hint. I tried to modify the function getBuildingHeight() but I have two problems:

1) The else branch is not called in this simple example if the height is not set. The returned height is 0.

function getBuildingHeight() {
        var h = 0;
        if ("height" in feature.properties) {
                h = feature.properties["height"];
        } else {
                h = 200;
        }
        return h;
}

2) feature.properties["height"].replace('m','') outputs the following error:
[osgEarth]* [Feature] Feature Script error on 'getBuildingHeight()': TypeError: undefined not callable

Any ideas?

Update Problem 1:
if ("height" in feature.properties) is always true. Even if "height" is not defined for a building. This is working:

function getBuildingHeight() {
    var h = feature.properties["height"];
    if (h > 0)
        return h;
               
    return 200;
}


               
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

I would stick with the example style.  

function getBuildingHeight() {
        if ("height" in feature.properties) {
                var h = feature.properties["height"];
                 return Math.max(h, 4.0);   //in case height is 0 return a reasonable height
        }
        return Math.floor((Math.random() * 5.0) + 4.0);  //return a random height or set this to a constant height

2) the .replace is there in case the unit is stored with height value.  As I said, it is easier to take a look at your data in QGIS and see if there is an attribute height and if it has a unit or not.  That test just finds the common height attributes from our OSM data but for specific areas, you would still need to look at what attributes are used and modify the javascript.  Or if you are more comfortable in a GIS package, add a new attribute that stores the heights and export a shapefile.  Then reference it like boston:

extrusion-height:        max([height], 4);
 
It is just easier in a GIS package to see all the attributes and unify the format on an extract.  Or do the same as that script is doing, generate random heights if there are no height values.  ArcMap uses Python or VB instead of Javascript but basically the same idea as the getBuildingHeight script.

--
Paul Levy : Pelican Mapping


On Wed, May 13, 2020 at 9:50 AM ElRudi [via osgEarth] <[hidden email]> wrote:
Thank you for the hint. I tried to modify the function getBuildingHeight() but I have two problems:

1) The else branch is not called in this simple example if the height is not set. The returned height is 0.

function getBuildingHeight() {
        var h = 0;
        if ("height" in feature.properties) {
                h = feature.properties["height"];
        } else {
                h = 200;
        }
        return h;
}

2) feature.properties["height"].replace('m','') outputs the following error:
[osgEarth]* [Feature] Feature Script error on 'getBuildingHeight()': TypeError: undefined not callable

Any ideas?


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Buildings-from-shapefile-tp7593153p7593165.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
ElRudi ElRudi
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

I have a geojson file with two buildings to test the height function.

if ("height" in feature.properties)

is true for both buildings, even if the height is only defined in one of them. So i cannot use this to check if the height is defined for a building and i'm checking, if the returned height is greater than zero.

I have another Javascript problem. Assume, that the height is set to 10 in the geojson file:

var h = feature.properties["height"];
return h + 10;

-> result: 1000 ???

var h = feature.properties["height"];
return h;

-> result: 10 as expected

var h = 10;
return h + 10;

->result: 20 as expected

Why is the first one not working? Multiplication works.

2) My question is: Why is the replace function not working for me?
plevy plevy
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

Can you attach or paste your data and the .earth.

Hard to answer your question as it could be a data, import or osgearth problem. 


On Wed, May 13, 2020, 11:54 AM ElRudi [via osgEarth] <[hidden email]> wrote:
I have a geojson file with two buildings to test the height function.

if ("height" in feature.properties)

is true for both buildings, even if the height is only defined in one of them. So i cannot use this to check if the height is defined for a building and i'm checking, if the returned height is greater than zero.

I have another Javascript problem. Assume, that the height is set to 10 in the geojson file:

var h = feature.properties["height"];
return h + 10;

-> result: 1000

var h = feature.properties["height"];
return h;

-> result: 10

var h = 10;
return h + 10;

->result: 20 as expected

Why is the first one not working? Multiplication works.

2) My question is: Why is the replace function not working for me?


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/Buildings-from-shapefile-tp7593153p7593167.html
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
ElRudi ElRudi
Reply | Threaded
Open this post in threaded view
|

Re: Buildings from shapefile

This post was updated on .
I've made an example geojson and earth file and attached them. There are four buildings in the geojson:

- one with the attribute "height" = 100 that is correctly shown
- one with "building:height" = 100 that is far too high because the function returns h+10
- one with "test:height" that is correct
- one without any height, that has the height of 200 instead of 40

This is my function:
                                function getBuildingHeight() {

                                        var h = feature.properties["height"];
                                        if (h > 0)
                                                return h;

                                        h = feature.properties["building:height"];
                                        if (h > 0)
                                                return h + 10;

                                        h = feature.properties["test:height"];
                                        if (h > 0) {
                                                h = 100;
                                                return h + 10;
                                        }

                                        if ("test:height" in feature.properties) {
                                                return 200;
                                        }
                                                                               
                                        return 40;
                                }

Update: I just found out, that the addition is working with parseFloat and you don't need replace('m',''):
h = parseFloat(feature.properties["building:height"]);

So the last question is: Why is ("test:height" in feature.properties) true for all buildings, even though "test:height" is only defined in one?

test.earth
test.geojson