Пример #1
0
        static Source decodeSource(XmlElement e, Project proj, int pass)
        {
            Source source = null;

            if (e != null)
            {
                if (pass == 0)
                {
                    // first pass: create the new source record
                    source = new Source();
#if TODO_DANI
                    source.setBaseURI(proj.getBaseURI());
#endif
                    source.setName(e.GetAttribute("name"));
                    source.setType(e.GetAttribute("type") == "raster" ? Source.SourceType.TYPE_RASTER : Source.SourceType.TYPE_FEATURE);
                    source.setURI(e.GetElementsByTagName("uri")[0].InnerText);
#if TODO_DANI
                    source.setFilterGraph(proj.getFilterGraph(e.GetAttribute("graph")));
#endif
                }
                else
                {
                    // second pass: reference other sources
                    source = proj.getSource(e.GetAttribute("name"));
                    source.setParentSource(proj.getSource(e.GetAttribute("parent")));
                }
            }
            return(source);
        }
Пример #2
0
        static Project decodeInclude(XmlElement e, Project proj)
        {
            if (e != null)
            {
                string uri = e.InnerText;
                if (!string.IsNullOrEmpty(uri))
                {
                    uri = PathUtils.getAbsPath(proj.getBaseURI(), uri);

                    Project include_proj = XmlSerializer.loadProject(uri);
                    if (include_proj != null)
                    {
                        proj.merge(include_proj);
                    }
                }
            }
            return(proj);
        }
Пример #3
0
        static Terrain decodeTerrain(XmlElement e, Project proj)
        {
            Terrain terrain = null;

            if (e != null)
            {
                terrain = new Terrain();
                terrain.setBaseURI(proj.getBaseURI());
                terrain.setName(e.GetAttribute("name"));
                terrain.setURI(e.GetElementsByTagName("uri")[0].InnerText);

                SRSResource resource = findSRSResource(proj.getResources(), e.GetAttribute("srs"));
                if (resource != null)
                {
                    terrain.setExplicitSRS(resource.getSRS());
                }
            }
            return(terrain);
        }
Пример #4
0
        static Project decodeInclude(XmlElement e, Project proj)
        {
            if (e != null)
            {
                string uri = e.InnerText;
                if (!string.IsNullOrEmpty(uri))
                {
                    uri = PathUtils.getAbsPath(proj.getBaseURI(), uri);

                    Project include_proj = XmlSerializer.loadProject(uri);
                    if (include_proj != null)
                    {
                        proj.merge(include_proj);
                    }
                }
            }
            return proj;
        }
Пример #5
0
        static Terrain decodeTerrain(XmlElement e, Project proj)
        {
            Terrain terrain = null;
            if (e != null)
            {
                terrain = new Terrain();
                terrain.setBaseURI(proj.getBaseURI());
                terrain.setName(e.GetAttribute("name"));
                terrain.setURI(e.GetElementsByTagName("uri")[0].InnerText);

                SRSResource resource = findSRSResource(proj.getResources(), e.GetAttribute("srs"));
                if (resource != null)
                    terrain.setExplicitSRS(resource.getSRS());
            }
            return terrain;
        }
Пример #6
0
 static Source decodeSource(XmlElement e, Project proj, int pass)
 {
     Source source = null;
     if (e != null)
     {
         if (pass == 0)
         {
             // first pass: create the new source record
             source = new Source();
     #if TODO_DANI
             source.setBaseURI(proj.getBaseURI());
     #endif
             source.setName(e.GetAttribute("name"));
             source.setType(e.GetAttribute("type") == "raster" ? Source.SourceType.TYPE_RASTER : Source.SourceType.TYPE_FEATURE);
             source.setURI(e.GetElementsByTagName("uri")[0].InnerText);
     #if TODO_DANI
             source.setFilterGraph(proj.getFilterGraph(e.GetAttribute("graph")));
     #endif
         }
         else
         {
             // second pass: reference other sources
             source = proj.getSource(e.GetAttribute("name"));
             source.setParentSource(proj.getSource(e.GetAttribute("parent")));
         }
     }
     return source;
 }
Пример #7
0
        static Resource decodeResource(XmlElement e, Project proj)
        {
            SRSResource a = new SRSResource();
            Resource resource = null;
            if (e != null)
            {
                string type = e.GetAttribute("type");
                resource = MogreGis.Registry.instance().createResourceByType(type);

                // try again with "Resource" suffix
                if (resource == null && !type.EndsWith("Resource", false, CultureInfo.InvariantCulture))
                    resource = MogreGis.Registry.instance().createResourceByType(type + "Resource");

                if (resource != null)
                {
                    resource.BaseUri = proj.getBaseURI();

                    resource.Name = e.GetAttribute("name");

                    string csv_tags = e.GetAttribute("tags");
                    if (!string.IsNullOrEmpty(csv_tags))
                    {
                        //std.istringstream iss(csv_tags);
                        //List<string> tokens = new List<string>((std.istream_iterator<string>(iss)), std.istream_iterator<string>());
                        string[] tokens = csv_tags.Split(',');
                        foreach (string i in tokens)
                            resource.addTag(i);
                    }

                    resource.addTag(e.GetAttribute("tags"));
                    XmlNodeList listuri = e.GetElementsByTagName("uri");
                    if (listuri.Count > 0)
                        resource.Uri = listuri[0].InnerText;

                    XmlNodeList prop_els = e.GetElementsByTagName("property");
                    foreach (XmlNode k in prop_els)
                    {
                        XmlElement k_e = (XmlElement)k;
                        string name = k_e.GetAttribute("name");
                        string value = k_e.GetAttribute("value");
                        resource.setProperty(new Property(name, value));
                    }

                    if (resource != null && resource is SRSResource)
                    {
                        parseSRSResource(e, (SRSResource)resource);
                    }
            #if TODO_PH
                    else if (resource != null && resource is RasterResource)
                    {
                        parseRasterResource(e, (RasterResource)resource);
                    }
            #endif
                }
                else
                {
                    //TODO osgGIS.notify( osg.WARN ) << "Unknown resource type: " << type << std.endl;
                }
            }
            return resource;
        }
Пример #8
0
        static Project decodeProject(XmlElement e, string source_uri)
        {
            if (e == null || !e.Name.Equals("project"))
                throw new ApplicationException("First XML element must be <project/> tag");

            Project project = null;
            if (e != null)
            {
                project = new Project();
                project.setSourceURI(source_uri);
                project.setName(e.GetAttribute("name"));
                project.setWorkingDirectory(e.GetAttribute("workdir"));

            #if TODO_DANI //includes
                // includes
                XmlNodeList includes = e.GetElementsByTagName("include");
                foreach (XmlNode j in includes)
                {
                    decodeInclude((XmlElement)j, project);
                }
            #endif
                // scripts
                XmlNodeList scripts = e.GetElementsByTagName("script");
                foreach (XmlNode j in scripts)
                {
                    Script script = decodeScript((XmlElement)j, project);
                    if (script != null)
                        project.getScripts().Add(script);
                }

                //some project variables.
                XmlNodeList engines = e.GetElementsByTagName("scriptEngine");
                foreach (XmlElement engine in engines)
                {
                    Registry.instance().LoadAndRegistryEngine(engine.GetAttribute("Class"), engine.GetAttribute("Assembly"));
                }

                XmlNodeList nl = e.GetElementsByTagName("mogreRender");
                foreach (XmlElement n in nl)
                {
                    decodeMogreRender(n, project);
                }

            #if !TODO_DANI //resources

                // resources
                XmlNodeList resources = e.GetElementsByTagName("resource");
                foreach (XmlNode j in resources)
                {
                    Resource resource = decodeResource((XmlElement)j, project);
                    if (resource != null)
                        project.getResources().Add(resource);
                }

            #endif

                // graphs
                XmlNodeList graphs = e.GetElementsByTagName("graph");
                foreach (XmlNode j in graphs)
                {
                    FilterGraph graph = decodeFilterGraph((XmlElement)j, project);
                    if (graph != null)
                        project.getFilterGraphs().Add(graph);
                }

            #if TODO_DANI //terrains

                // terrains (depends on resources)
                XmlNodeList terrains = e.GetElementsByTagName("terrain");
                foreach (XmlNode j in terrains)
                {
                    Terrain terrain = decodeTerrain((XmlElement)j, project);
                    if (terrain != null)
                        project.getTerrains().Add(terrain);
                }

            #endif

                // sources - 2 passes, since a source can reference another source
                XmlNodeList sources = e.GetElementsByTagName("source");
                foreach (XmlNode j in sources)
                {

                    // TODO Dani, meter esto en un try catch

                    Source source = decodeSource((XmlElement)j, project, 0);
                    if (source != null)
                    {
                        project.getSources().Add(source);

            #if TODO_DANI
                        // also add each source as a feature layer resource
                        Resource resource = MogreGis.Registry.instance().createResourceByType("FeatureLayerResource");
                        resource.setBaseURI(project.getBaseURI());
                        resource.setURI(source.getURI());
                        resource.setName(source.getName());
                        project.getResources().Add(resource);
            #endif
                    }
                }
                foreach (XmlNode j in sources)
                {
                    decodeSource((XmlElement)j, project, 1);
                }

                //#if TODO_DANI //layers

                // layers
                XmlNodeList layers = e.GetElementsByTagName("layer");
                foreach (XmlNode j in layers)
                {
                    BuildLayer layer = decodeLayer((XmlElement)j, project);
                    if (layer != null)
                    {
                        project.getLayers().Add(layer);

                        // automatically add a target for this layer alone:
                        BuildTarget layer_target = new BuildTarget();
                        layer_target.setName(layer.getName());
                        layer_target.addLayer(layer);
                        project.getTargets().Add(layer_target);
                    }
                }

                //#endif

            #if TODO_DANI //targets

                // targets
                XmlNodeList targets = e.GetElementsByTagName("target");
                foreach (XmlNode j in targets)
                {
                    BuildTarget target = decodeTarget((XmlElement)j, project);
                    if (target != null)
                        project.getTargets().Add(target);
                }

            #endif

            #if TODO_DANI //maps

                // maps
                XmlNodeList maps = e.GetElementsByTagName("map");
                foreach (XmlNode j in maps)
                {
                    RuntimeMap map = decodeRuntimeMap((XmlElement)j, project);
                    if (map != null)
                        project.getMaps().Add(map);
                }

            #endif

            }
            return project;
        }
Пример #9
0
        static BuildLayer decodeLayer(XmlElement e, Project proj)
        {
            BuildLayer layer = null;
            if (e != null)
            {
                layer = new BuildLayer();

            #if TODO_DANI
                layer.setBaseURI(proj.getBaseURI());
            #endif

                layer.setName(e.GetAttribute("name"));

                string type = e.GetAttribute("type");
                if (type == "correlated")
                    layer.setType(BuildLayer.LayerType.TYPE_CORRELATED);
                else if (type == "gridded")
                    layer.setType(BuildLayer.LayerType.TYPE_GRIDDED);
                else if (type == "quadtree" || type == "new")
                    layer.setType(BuildLayer.LayerType.TYPE_QUADTREE);

                string source = e.GetAttribute("source");
                layer.setSource(proj.getSource(source));

                string terrain = e.GetAttribute("terrain");
                layer.setTerrain(proj.getTerrain(terrain));

                layer.setTargetPath(e.GetAttribute("target"));

                XmlNodeList slices = e.GetElementsByTagName("slice");
                foreach (XmlNode i in slices)
                {
                    BuildLayerSlice slice = decodeSlice((XmlElement)i, proj);
                    if (slice != null)
                        layer.getSlices().Add(slice);
                }

            #if TODO_DANI
                XmlNodeList props = e.GetElementsByTagName("property");
                foreach (XmlNode i in props)
                {
                    XmlElement k_e = (XmlElement)i;
                    string name = k_e.GetAttribute("name");
                    string value = k_e.GetAttribute("value");
                    layer.getProperties().Add(new Property(name, value));
                }

                XmlNodeList env_props = e.GetElementsByTagName("env_property");
                foreach (XmlNode i in env_props)
                {
                    XmlElement k_e = (XmlElement)i;
                    string name = k_e.GetAttribute("name");
                    string value = k_e.GetAttribute("value");
                    layer.getEnvProperties().Add(new Property(name, value));
                }
            #endif
            }
            return layer;
        }
Пример #10
0
        static Project decodeProject(XmlElement e, string source_uri)
        {
            if (e == null || !e.Name.Equals("project"))
            {
                throw new ApplicationException("First XML element must be <project/> tag");
            }

            Project project = null;

            if (e != null)
            {
                project = new Project();
                project.setSourceURI(source_uri);
                project.setName(e.GetAttribute("name"));
                project.setWorkingDirectory(e.GetAttribute("workdir"));

#if TODO_DANI //includes
                // includes
                XmlNodeList includes = e.GetElementsByTagName("include");
                foreach (XmlNode j in includes)
                {
                    decodeInclude((XmlElement)j, project);
                }
#endif
                // scripts
                XmlNodeList scripts = e.GetElementsByTagName("script");
                foreach (XmlNode j in scripts)
                {
                    Script script = decodeScript((XmlElement)j, project);
                    if (script != null)
                    {
                        project.getScripts().Add(script);
                    }
                }

                //some project variables.
                XmlNodeList engines = e.GetElementsByTagName("scriptEngine");
                foreach (XmlElement engine in engines)
                {
                    Registry.instance().LoadAndRegistryEngine(engine.GetAttribute("Class"), engine.GetAttribute("Assembly"));
                }

                XmlNodeList nl = e.GetElementsByTagName("mogreRender");
                foreach (XmlElement n in nl)
                {
                    decodeMogreRender(n, project);
                }

#if !TODO_DANI //resources
                // resources
                XmlNodeList resources = e.GetElementsByTagName("resource");
                foreach (XmlNode j in resources)
                {
                    Resource resource = decodeResource((XmlElement)j, project);
                    if (resource != null)
                    {
                        project.getResources().Add(resource);
                    }
                }
#endif

                // graphs
                XmlNodeList graphs = e.GetElementsByTagName("graph");
                foreach (XmlNode j in graphs)
                {
                    FilterGraph graph = decodeFilterGraph((XmlElement)j, project);
                    if (graph != null)
                    {
                        project.getFilterGraphs().Add(graph);
                    }
                }

#if TODO_DANI //terrains
                // terrains (depends on resources)
                XmlNodeList terrains = e.GetElementsByTagName("terrain");
                foreach (XmlNode j in terrains)
                {
                    Terrain terrain = decodeTerrain((XmlElement)j, project);
                    if (terrain != null)
                    {
                        project.getTerrains().Add(terrain);
                    }
                }
#endif

                // sources - 2 passes, since a source can reference another source
                XmlNodeList sources = e.GetElementsByTagName("source");
                foreach (XmlNode j in sources)
                {
                    // TODO Dani, meter esto en un try catch

                    Source source = decodeSource((XmlElement)j, project, 0);
                    if (source != null)
                    {
                        project.getSources().Add(source);

#if TODO_DANI
                        // also add each source as a feature layer resource
                        Resource resource = MogreGis.Registry.instance().createResourceByType("FeatureLayerResource");
                        resource.setBaseURI(project.getBaseURI());
                        resource.setURI(source.getURI());
                        resource.setName(source.getName());
                        project.getResources().Add(resource);
#endif
                    }
                }
                foreach (XmlNode j in sources)
                {
                    decodeSource((XmlElement)j, project, 1);
                }

                //#if TODO_DANI //layers

                // layers
                XmlNodeList layers = e.GetElementsByTagName("layer");
                foreach (XmlNode j in layers)
                {
                    BuildLayer layer = decodeLayer((XmlElement)j, project);
                    if (layer != null)
                    {
                        project.getLayers().Add(layer);

                        // automatically add a target for this layer alone:
                        BuildTarget layer_target = new BuildTarget();
                        layer_target.setName(layer.getName());
                        layer_target.addLayer(layer);
                        project.getTargets().Add(layer_target);
                    }
                }

                //#endif

#if TODO_DANI //targets
                // targets
                XmlNodeList targets = e.GetElementsByTagName("target");
                foreach (XmlNode j in targets)
                {
                    BuildTarget target = decodeTarget((XmlElement)j, project);
                    if (target != null)
                    {
                        project.getTargets().Add(target);
                    }
                }
#endif

#if TODO_DANI //maps
                // maps
                XmlNodeList maps = e.GetElementsByTagName("map");
                foreach (XmlNode j in maps)
                {
                    RuntimeMap map = decodeRuntimeMap((XmlElement)j, project);
                    if (map != null)
                    {
                        project.getMaps().Add(map);
                    }
                }
#endif
            }
            return(project);
        }
Пример #11
0
        static BuildLayer decodeLayer(XmlElement e, Project proj)
        {
            BuildLayer layer = null;

            if (e != null)
            {
                layer = new BuildLayer();

#if TODO_DANI
                layer.setBaseURI(proj.getBaseURI());
#endif

                layer.setName(e.GetAttribute("name"));

                string type = e.GetAttribute("type");
                if (type == "correlated")
                {
                    layer.setType(BuildLayer.LayerType.TYPE_CORRELATED);
                }
                else if (type == "gridded")
                {
                    layer.setType(BuildLayer.LayerType.TYPE_GRIDDED);
                }
                else if (type == "quadtree" || type == "new")
                {
                    layer.setType(BuildLayer.LayerType.TYPE_QUADTREE);
                }

                string source = e.GetAttribute("source");
                layer.setSource(proj.getSource(source));

                string terrain = e.GetAttribute("terrain");
                layer.setTerrain(proj.getTerrain(terrain));

                layer.setTargetPath(e.GetAttribute("target"));

                XmlNodeList slices = e.GetElementsByTagName("slice");
                foreach (XmlNode i in slices)
                {
                    BuildLayerSlice slice = decodeSlice((XmlElement)i, proj);
                    if (slice != null)
                    {
                        layer.getSlices().Add(slice);
                    }
                }

#if TODO_DANI
                XmlNodeList props = e.GetElementsByTagName("property");
                foreach (XmlNode i in props)
                {
                    XmlElement k_e   = (XmlElement)i;
                    string     name  = k_e.GetAttribute("name");
                    string     value = k_e.GetAttribute("value");
                    layer.getProperties().Add(new Property(name, value));
                }

                XmlNodeList env_props = e.GetElementsByTagName("env_property");
                foreach (XmlNode i in env_props)
                {
                    XmlElement k_e   = (XmlElement)i;
                    string     name  = k_e.GetAttribute("name");
                    string     value = k_e.GetAttribute("value");
                    layer.getEnvProperties().Add(new Property(name, value));
                }
#endif
            }
            return(layer);
        }
Пример #12
0
        static Resource decodeResource(XmlElement e, Project proj)
        {
            SRSResource a        = new SRSResource();
            Resource    resource = null;

            if (e != null)
            {
                string type = e.GetAttribute("type");
                resource = MogreGis.Registry.instance().createResourceByType(type);

                // try again with "Resource" suffix
                if (resource == null && !type.EndsWith("Resource", false, CultureInfo.InvariantCulture))
                {
                    resource = MogreGis.Registry.instance().createResourceByType(type + "Resource");
                }

                if (resource != null)
                {
                    resource.BaseUri = proj.getBaseURI();

                    resource.Name = e.GetAttribute("name");

                    string csv_tags = e.GetAttribute("tags");
                    if (!string.IsNullOrEmpty(csv_tags))
                    {
                        //std.istringstream iss(csv_tags);
                        //List<string> tokens = new List<string>((std.istream_iterator<string>(iss)), std.istream_iterator<string>());
                        string[] tokens = csv_tags.Split(',');
                        foreach (string i in tokens)
                        {
                            resource.addTag(i);
                        }
                    }

                    resource.addTag(e.GetAttribute("tags"));
                    XmlNodeList listuri = e.GetElementsByTagName("uri");
                    if (listuri.Count > 0)
                    {
                        resource.Uri = listuri[0].InnerText;
                    }


                    XmlNodeList prop_els = e.GetElementsByTagName("property");
                    foreach (XmlNode k in prop_els)
                    {
                        XmlElement k_e   = (XmlElement)k;
                        string     name  = k_e.GetAttribute("name");
                        string     value = k_e.GetAttribute("value");
                        resource.setProperty(new Property(name, value));
                    }

                    if (resource != null && resource is SRSResource)
                    {
                        parseSRSResource(e, (SRSResource)resource);
                    }
#if TODO_PH
                    else if (resource != null && resource is RasterResource)
                    {
                        parseRasterResource(e, (RasterResource)resource);
                    }
#endif
                }
                else
                {
                    //TODO osgGIS.notify( osg.WARN ) << "Unknown resource type: " << type << std.endl;
                }
            }
            return(resource);
        }