osgearth 为何不支持geojson
本帖最后由 liyihongcug 于 2020-3-24 14:39 编辑没有找到driver。 有啥方法可以间接读取写入
osgearth10 较大进步 支3d瓦片和gltf格式。但还是没有发现json。只考虑WGS84
docs.osgearth.org en latest user features.html 解决。是支持的。 解决思考过程:这个是矢量数据,可以往shapefile上挂靠。
所以最红如下解决
<model name="world_boundaries" driver="feature_geom">
<features name="world" driver="ogr">
<url>D:/CHINA.json</url>
<build_spatial_index>true</build_spatial_index>
<convert type="line"/>
</features>
<layout tile_size="500000" crop_features="true">
<level max_range="1e10"/>
</layout>
<styles>
<style type="text/css">
world {
stroke: #ffff00;
stroke-width: 2px;
stroke-tessellation-size: 100km;
render-depth-offset-min-bias: 1000;
}
</style>
</styles>
</model> 实现对矢量文件的读写操作
#include <osg/Notify>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
using namespace osgEarth::Features;
using namespace osgEarth::Drivers;
using namespace osgEarth::Symbology;
#include <osgEarthFeatures/GeometryUtils>
std::string attributeTypeToString( AttributeType type )
{
switch (type)
{
case ATTRTYPE_BOOL: return "Boolean";
case ATTRTYPE_DOUBLE: return "Double";
case ATTRTYPE_INT: return "Integer";
case ATTRTYPE_STRING: return "String";
default:return "Unspecified";
}
}
std::string indent = " ";
void printStats(FeatureSource* features)
{
std::cout << "Feature Count:" << features->getFeatureCount() << std::endl;
std::cout << "Geometry Type:" << osgEarth::Symbology::Geometry::toString( features->getGeometryType() ) << std::endl;
//Print the schema
const FeatureSchema schema = features->getSchema();
std::cout << "Schema:" << std::endl;
for (FeatureSchema::const_iterator itr = schema.begin(); itr != schema.end(); ++itr)
{
std::cout << indent << itr->first << ": " << attributeTypeToString(itr->second) << std::endl;
}
std::cout << std::endl;
}
void printFeature( Feature* feature )
{
std::cout << "FID: " << feature->getFID() << std::endl;
for (AttributeTable::const_iterator itr = feature->getAttrs().begin(); itr != feature->getAttrs().end(); ++itr)
{
std::cout
<< indent
<< itr->first << "=" << itr->second.getString() << " ("
<< (itr->second.first == ATTRTYPE_INT? "integer" :
itr->second.first == ATTRTYPE_DOUBLE? "double" :
itr->second.first == ATTRTYPE_BOOL? "bool" :
"string")
<< ")" << std::endl;
}
//Print out the geometry
Geometry* geom = feature->getGeometry();
if (geom)
{
std::cout << indent << GeometryUtils::geometryToWKT( geom ) << std::endl;
}
std::cout << std::endl;
}
void printAllFeatures(FeatureSource* features)
{
osg::ref_ptr< FeatureCursor > cursor = features->createFeatureCursor();
while (cursor.valid() && cursor->hasMore())
{
osg::ref_ptr< Feature > feature = cursor->nextFeature();
printFeature( feature.get() );
}
}
int
usage( const std::string& msg )
{
if ( !msg.empty() )
{
std::cout << msg << std::endl;
}
std::cout
<< std::endl
<< "USAGE: osgearth_featureinfo filename" << std::endl
<< std::endl
<< " --printfeatures ; Prints all features in the source" << std::endl
<< " --delete fid ; Deletes the given FID from the source." << std::endl
<< " --fid fid ; Displays the given FID." << std::endl
<< std::endl;
return -1;
}
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
if (argc < 2)
{
return usage("");
}
std::vector< FeatureID > toDelete;
int fid;
while (arguments.read("--delete", fid))
{
toDelete.push_back( fid );
}
std::vector< FeatureID > fids;
while (arguments.read("--fid", fid))
{
fids.push_back( fid );
}
bool printFeatures = false;
if (arguments.read("--printfeatures" )) printFeatures = true;
std::string filename;
//Get the first argument that is not an option
for(int pos=1;pos<arguments.argc();++pos)
{
if (!arguments.isOption(pos))
{
filename= arguments[ pos ];
}
}
if (filename.empty())
{
return usage( "Please provide a filename" );
}
bool write = toDelete.size() > 0;
//Open the feature source
OGRFeatureOptions featureOpt;
featureOpt.url() = filename;
featureOpt.openWrite() = write;
osg::ref_ptr< FeatureSource > features = FeatureSourceFactory::create( featureOpt );
Status s = features->open();
if (s.isError())
return usage(s.message());
//Delete any features if requested
if (toDelete.size() > 0)
{
for (unsigned int i = 0; i < toDelete.size(); ++i)
{
FeatureID fid = toDelete;
std::cout << "Deleting Feature " << fid << std::endl;
features->deleteFeature( fid );
}
}
else if (fids.size() > 0)
{
//Print out any specific FIDs
for (unsigned int i = 0; i < fids.size(); ++i)
{
FeatureID fid = fids;
osg::ref_ptr< Feature > feature = features->getFeature( fid );
if (feature.valid())
{
printFeature( feature.get() );
}
else
{
std::cout << "Couldn't get feature " << fid << std::endl;
}
}
}
else
{
//Print out feature info
printStats( features.get() );
if (printFeatures)
{
printAllFeatures( features.get() );
}
}
return 0;
}
一个大下午时间,调试几十次脑袋都昏了,尽管比算法简单很多,但不容易。
动态库不匹配源码理查,不知道哪个编译的东西死活有问题,也不可能一个人做完所哟事情
页:
[1]