查看: 1122|回复: 3

osgearth 为何不支持geojson

[复制链接]
  • TA的每日心情
    开心
    2020-3-20 17:50
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2020-3-23 11:03:10 | 显示全部楼层 |阅读模式
    本帖最后由 liyihongcug 于 2020-3-24 14:39 编辑

    没有找到driver。 有啥方法可以间接读取写入

    osgearth10 较大进步 支3d瓦片和gltf格式。但还是没有发现json。  只考虑WGS84
    docs.osgearth.org en latest user features.html
  • TA的每日心情
    开心
    2020-3-20 17:50
  • 签到天数: 1 天

    [LV.1]初来乍到

     楼主| 发表于 2020-3-24 14:08:46 | 显示全部楼层
    解决。是支持的。 解决思考过程:这个是矢量数据,可以往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>
  • TA的每日心情
    开心
    2020-3-20 17:50
  • 签到天数: 1 天

    [LV.1]初来乍到

     楼主| 发表于 2020-3-25 10:25:36 | 显示全部楼层
    实现对矢量文件的读写操作
    #include <osg/Notify>

    #include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>

    using namespace osgEarth::Features;
    using namespace osgEarth:rivers;
    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 [options] 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( "lease 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[i];
                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[i];
                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;
    }
  • TA的每日心情
    开心
    2020-3-20 17:50
  • 签到天数: 1 天

    [LV.1]初来乍到

     楼主| 发表于 2020-4-10 19:16:35 | 显示全部楼层
    一个大下午时间,调试几十次脑袋都昏了,尽管比算法简单很多,但不容易。
    动态库不匹配源码理查,不知道哪个编译的东西死活有问题,也不可能一个人做完所哟事情
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    OSG中国官方论坛-有您OSG在中国才更好

    网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

    联系我们

    • 工作时间:09:00--18:00
    • 反馈邮箱:1315785073@qq.com
    快速回复 返回顶部 返回列表