예제 #1
0
        /**
         * Processes a single node into a collection of nodes.
         *
         * @param input
         *      Individual node to process
         * @param env
         *      Contextual compilation environment
         * @return
         *      Resulting node list
         */
        public virtual AttributedNodeList process(AttributedNode input, FilterEnv env)
        {
            AttributedNodeList output = new AttributedNodeList();

            output.Add(input);
            return(output);
        }
예제 #2
0
        /**
         * Processes a single feature into a collection of nodes.
         *
         * @param input
         *      Individual feature to process
         * @param env
         *      Contextual compilation environment
         * @return
         *      Resulting node list
         */
        public virtual AttributedNodeList process(Feature input, FilterEnv env)
        {
            AttributedNodeList output = new AttributedNodeList();

            //NOP - never called
            return(output);
        }
예제 #3
0
 override public FeatureList process(FeatureList input, FilterEnv env)
 {
     foreach (Feature feature in input)
     {
         CoordinateSystemFactory csf      = new CoordinateSystemFactory();
         ICoordinateSystem       cssource = csf.CreateFromWkt(((SharpMapSpatialReference)feature.getGeometry().SpatialReference).CoordinateSystem.WKT);
         ICoordinateSystem       cstarget;
         if (translateScript != null)
         {
             //Console.WriteLine(Registry.instance().GetEngine("Python").run(TranslateScript).asString());
             cstarget = csf.CreateFromWkt(Registry.instance().GetEngine("Python").run(TranslateScript).asString());
         }
         else
         {
             cstarget = csf.CreateFromWkt(env.getInputSRS().WKT);
         }
         CoordinateTransformationFactory ctf = new CoordinateTransformationFactory();
         ICoordinateTransformation       ct  = ctf.CreateFromCoordinateSystems(cssource, cstarget);
         //if (feature.getGeometry().GeometryType == GeometryType2.Point)
         //{
         //    Point p = (Point)feature.getGeometry();
         //GeometryTransform.TransformPoint(feature, ct.MathTransform);
         Geometry geom    = feature.getGeometry();
         Geometry geomRst = GeometryTransform.TransformGeometry(geom, ct.MathTransform);
         feature.setGeometry(geomRst);
         //}
     }
     return(input);
 }
예제 #4
0
        // FeatureFilter overrides
        public FeatureList process(Feature input, FilterEnv env)
        {
            FeatureList output;

            GeoShapeList shapes = input.getShapes();

            GeoShapeList new_shapes;

            double b = getDistance();

            if (env.getInputSRS().isGeographic())
            {
                // for geo, convert from meters to degrees
                //TODO: we SHOULD do this for each and every feature buffer segment, but
                //  for how this is a shortcut approximation.
                double   bc  = b / 1.4142;
                Vector2D vec = new Vector2D(bc, bc); //vec.normalize();
                GeoPoint c   = input.getExtent().getCentroid();
                Vector2D p0  = new Vector2D(c.X, c.Y);
                Vector2D p1;
                Units.convertLinearToAngularVector(vec, Units.METERS, Units.DEGREES, p0, p1);
                b = (p1 - p0).GetLength();
            }

            foreach (GeoPointList i in shapes)
            {
                GeoPartList new_parts;
                GeoShape    shape = i;

                if (shape.getShapeType() == GeoShape.ShapeType.TYPE_POLYGON)
                {
                    GeoShape new_shape = new GeoShape(GeoShape.ShapeType.TYPE_POLYGON, shape.getSRS());
                    bufferPolygons(shape, b, out new_shape.getParts());
                    new_shapes.Add(new_shape);
                }
                else if (shape.getShapeType() == GeoShape.ShapeType.TYPE_LINE)
                {
                    if (getConvertToPolygon())
                    {
                        GeoShape new_shape = new GeoShape(GeoShape.ShapeType.TYPE_POLYGON, shape.getSRS());
                        bufferLinesToPolygons(shape, b, new_shape);
                        new_shapes.Add(new_shape);
                    }
                    else
                    {
                        GeoShape new_shape = new GeoShape(GeoShape.ShapeType.TYPE_LINE, shape.getSRS());
                        bufferLinesToLines(shape, b, new_shape);
                        new_shapes.Add(new_shape);
                    }
                }
            }

            if (new_shapes.Count > 0)
            {
                input.getShapes().swap(new_shapes);
            }

            output.Add(input);
            return(output);
        }
예제 #5
0
        /**
         * Processes a single fragment into fragment(s). Override this method
         * in your implementation to process individual drawables into more
         * fragments.
         *
         * @param input
         *      Single fragment to convert
         * @param env
         *      Contextual compilation information
         * @return
         *      The converted input data. The default implementation of this
         *      method returns the input data.
         */
        public virtual FragmentList process(Fragment drawable, FilterEnv env)
        {
            FragmentList output = new FragmentList();

            output.Add(drawable);
            return(output);
        }
예제 #6
0
        /**
         * Processes a single Feature.
         *
         * @param input
         *      Individual Feature to process.
         * @param env
         *      Runtime processing environment.
         * @return
         *      A collection of Feature instances. The default implementation
         *      of this method just returns the input in a list.
         */
        public virtual FeatureList process(Feature input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            output.Add(input);
            return(output);
        }
예제 #7
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            MogreApp.setLocations(prj.getMogreLocations());
            SetupMogre();
            Mogre.SceneManager sm = app.SceneManager;

            foreach (MogreGis.FilterGraph graph in prj.getFilterGraphs())
            {
                foreach (osgGISProjects.Source source in prj.getSources())
                {
                    if (Path.GetExtension(source.getURI()) != ".shp")
                    {
                        throw new NotImplementedException();
                    }

                    if (source.getName() == graph.getName())
                    {
                        MogreGis.FilterEnv   env         = null;
                        MogreGis.FeatureList featureList = null;

                        FeatureDataSet ds = new FeatureDataSet();
                        source.DataSource.Open();
                        source.DataSource.ExecuteIntersectionQuery(source.DataSource.GetExtents(), ds);
                        source.DataSource.Close();
                        FeatureDataTable features = (FeatureDataTable)ds.Tables[0];
                        featureList = MogreGis.Feature.DataTableToList(features);

                        foreach (Script script in prj.getScripts())
                        {
                            Registry.instance().GetEngine("Python").run(script);
                        }

                        foreach (Feature feature in featureList)
                        {
                            SharpMapSpatialReferenceFactory smsrf = new SharpMapSpatialReferenceFactory();
                            ShapeFile shp = new ShapeFile(source.getURI());
                            shp.Open();
                            SharpMapSpatialReference sr;
                            sr = (SharpMapSpatialReference)smsrf.createSRSfromWKT(shp.CoordinateSystem.WKT);
                            feature.getGeometry().SpatialReference = sr;
                        }

                        env = new MogreGis.FilterEnv(sm, "env" + graph.getName());
                        env.setScriptEngine(Registry.instance().GetEngine("Python"));
                        foreach (MogreGis.Filter filter in graph.getFilters())
                        {
                            if (filter is MogreGis.FragmentFilter)
                            {
                                (filter as MogreGis.FragmentFilter).process(featureList, env);
                            }
                            if (filter is MogreGis.FeatureFilter)
                            {
                                featureList = (filter as MogreGis.FeatureFilter).process(featureList, env);
                            }
                        }
                    }
                }
            }
            app.getRoot().StartRendering();
        }
예제 #8
0
        /**
         * Gets a copy of the instance, copying output data to the input slots.
         * Specifically advance() will make a copy and move the source's output
         * spatial reference to be the new object's input spatial reference.
         *
         * @return A new FilterEnv
         */
        public FilterEnv advance()
        {
            FilterEnv a = clone();

            a.setInputSRS(getOutputSRS());
            a.setOutputSRS(getOutputSRS());
            return(a);
        }
예제 #9
0
        public override FeatureList process(Feature input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            if (transform != null && !transform.Identity())
            {
                foreach (GeoShape shape in input.getShapes())
                {
                    XformVisitor visitor = new XformVisitor();
                    visitor.trans = transform;
                    shape.accept(visitor);
                }
            }

            output.Add(input);
            return(output);

#if TODO
            // resolve the xlate shortcut
            Matrix working_matrix = xform_matrix;

            // TODO: this can go into process(FeatureList) instead of running for every feature..
            if (getTranslateScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getTranslateScript(), input, env);
                if (r.isValid())
                {
                    working_matrix = Matrix.translate(r.asVec3());
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            if (working_srs != null || (working_matrix != null && !working_matrix.IsIdentity))
            {
                foreach (GeoShape shape in input.getShapes())
                {
                    if (working_matrix != null && !working_matrix.IsIdentity)
                    {
                        XformVisitor visitor;
                        visitor.mat = working_matrix;
                        shape.accept(visitor);
                    }

                    if (working_srs != null && !working_srs.equivalentTo(env.getInputSRS()))
                    {
                        working_srs.transformInPlace(shape);
                    }
                }
            }

            output.Add(input);
            return(output);
#endif
            throw new NotImplementedException();
        }
예제 #10
0
        // FragmentFilter overrides
        protected virtual FragmentList process(FeatureList input, FilterEnv env)
        {
            // load and cache the font
            if (!string.IsNullOrEmpty(getFontName()) && !font.valid())
            {
                font = osgText.readFontFile(getFontName());
            }

            return(base.process(input, env));
        }
예제 #11
0
        public override FeatureList process(FeatureList input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            //Boolean encontrado = false;
            SharpMap.Geometries.BoundingBox boundingBox = new SharpMap.Geometries.BoundingBox(longitudeMin, latitudeMin, longitudeMax, latitudeMax);

            foreach (Feature feature in input)
            {
                //if type of features is Point
                if (feature.row.Geometry is SharpMap.Geometries.Point)
                {
                    SharpMap.Geometries.Point p = (SharpMap.Geometries.Point)feature.row.Geometry;
                    if (boundingBox.Contains(p.GetBoundingBox()))
                    {
                        output.Add(feature);
                    }
                }
                //if type of features is Polygon
                else if (feature.row.Geometry is SharpMap.Geometries.Polygon)
                {
                    SharpMap.Geometries.Polygon polygon = (SharpMap.Geometries.Polygon)feature.row.Geometry;
                    if (boundingBox.Contains(polygon.GetBoundingBox()))
                    {
                        output.Add(feature);
                    }
                }
                //if type of features is MultiPolygon
                else if (feature.row.Geometry is SharpMap.Geometries.MultiPolygon)
                {
                    SharpMap.Geometries.MultiPolygon mp = (SharpMap.Geometries.MultiPolygon)feature.row.Geometry;
                    SharpMap.Geometries.BoundingBox  bb = mp.GetBoundingBox();
                    if (boundingBox.Contains(bb))
                    {
                        output.Add(feature);
                    }
                }
            }

            if (successor != null)
            {
                if (successor is FeatureFilter)
                {
                    FeatureFilter filter = (FeatureFilter)successor;
                    FeatureList   l      = filter.process(output, env);
                }
                else if (successor is FragmentFilter)
                {
                    FragmentFilter filter = (FragmentFilter)successor;
                    FragmentList   l      = filter.process(output, env);
                }
            }

            return(output);
        }
예제 #12
0
        /**
         * Processes a collection of features into fragments. Override this
         * method in your implementation to convert batches of features into
         * fragments.
         *
         * @param input
         *      Batch of features to convert into drawables
         * @param env
         *      Contextual compilation information
         * @return
         *      The converted input data. The default implementation of this
         *      method returns an empty set.
         */
        public virtual FragmentList process(FeatureList input, FilterEnv env)
        {
            FragmentList output = new FragmentList();

            foreach (Feature i in input)
            {
                FragmentList interim = process(i, env);
                output.InsertRange(output.Count, interim);
            }
            return(output);
        }
예제 #13
0
        /**
         * Processes a collection of features into a collection of nodes.
         *
         * @param input
         *      Batch of features to process
         * @param env
         *      Contextual compilation environment
         * @return
         *      Resulting node list
         */
        public virtual AttributedNodeList process(FeatureList input, FilterEnv env)
        {
            AttributedNodeList output = new AttributedNodeList();

            foreach (Feature i in input)
            {
                AttributedNodeList interim = process(i, env);
                output.InsertRange(output.Count, interim);
            }
            return(output);
        }
예제 #14
0
        // NodeFilter overrides
        protected virtual AttributedNodeList process(FragmentList input, FilterEnv env)
        {
            AttributedNodeList nodes;

            osg.Geode geode = null;
            for (FragmentList.const_iterator i = input.begin(); i != input.end(); i++)
            {
                Fragment frag = i;

                AttributeList frag_attrs = frag.getAttributes();

                if (!geode)
                {
                    geode = new osg.Geode();
                    nodes.Add(new AttributedNode(geode, frag_attrs));
                }

                for (DrawableList.const_iterator d = frag.getDrawables().begin(); d != frag.getDrawables().end(); d++)
                {
                    geode.addDrawable(d.get());
                }

                bool retire_geode = false;

                // if a fragment name is set, apply it
                if (frag.hasName())
                {
                    geode.addDescription(frag.getName());
                    retire_geode = true;
                }

                if (getEmbedAttributes())
                {
                    embedAttributes(geode, frag_attrs);
                    retire_geode = true;
                }

                // If required, reset the geode point so that the next fragment gets placed in a new geode.
                if (retire_geode)
                {
                    geode = null;
                }
            }

            // with multiple geodes or fragment names, disable geode combining to preserve the node decription.
            if (nodes.Count > 1)
            {
                env.getOptimizerHints().exclude(osgUtil.Optimizer.MERGE_GEODES);
            }

            return(process(nodes, env));
        }
예제 #15
0
        /**
         * GeoPoint
         *
         * GeomUtils::clampToTerrain( const GeoPoint& input, osg::Node* terrain, SpatialReference* terrain_srs, SmartReadCallback* reader )
         *
         * {
         *
         * GeoPoint output = GeoPoint::invalid();
         *
         *
         *
         * if ( terrain && terrain_srs )
         *
         * {
         *
         * double out_hat = 0;
         *
         * osg::ref_ptr<LineSegmentIntersector2> isector =
         *
         *  createClampingIntersector( input, out_hat );
         *
         *
         *
         * //GeoPoint p_world = terrain_srs->transform( input );
         *
         *
         *
         * //osg::Vec3d clamp_vec;
         *
         * //osg::ref_ptr<osgUtil::LineSegmentIntersector> isector;
         *
         *
         *
         * //if ( terrain_srs->isGeocentric() )
         *
         * //{
         *
         * //    clamp_vec = p_world;
         *
         * //    clamp_vec.normalize();
         *
         *
         *
         * //    isector = new osgUtil::LineSegmentIntersector(
         *
         * //        clamp_vec * terrain_srs->getEllipsoid().getSemiMajorAxis() * 1.2,
         *
         * //        osg::Vec3d(0, 0, 0) );
         *
         * //}
         *
         * //else
         *
         * //{
         *
         * //    clamp_vec.set(0, 0, 1);
         *
         * //    osg::Vec3d ext_vec = clamp_vec * 1e6;
         *
         * //    isector = new LineSegmentIntersector(
         *
         * //        p_world + ext_vec,
         *
         * //        p_world - ext_vec );
         *
         * //}
         *
         *
         *
         * RelaxedIntersectionVisitor iv;
         *
         * iv.setIntersector( isector.get() );
         *
         * iv.setReadCallback( reader );
         *
         *
         *
         * //IntersectionVisitor iv;
         *
         * //iv.setIntersector( isector.get() );
         *
         * //iv.setReadCallback( new SimpleReader() );
         *
         *
         *
         * terrain->accept( iv );
         *
         * if ( isector->containsIntersections() )
         *
         * {
         *
         *  output = GeoPoint( isector->getFirstIntersection().getWorldIntersectPoint(), terrain_srs );
         *
         * }
         *
         * }
         *
         */
#endif

        private static GeoPoint ClampToTerrain(GeoPoint input, FilterEnv env)
        {
            //if (env.getTerrainNode() != null)
            //{
            //    //Falta por implementar GeomUtils.ClampToTerrain y env.getTerrainReadCallback.
            //    //return GeomUtils.ClampToTerrain (input, env.getTerrainNode(), env.getTerrainSRS(),env.getTerrainReadCallback());
            //    return
            //}
            //else
            //{
            return(input);
            //}
        }
예제 #16
0
        public override FilterStateResult traverse(FilterEnv in_env)
        {
            FilterStateResult result = new FilterStateResult();

            current_env = in_env.advance();

            if (in_features.Count > 0)
            {
                out_nodes = filter.process(in_features, current_env);
            }
            else if (in_fragments.Count > 0)
            {
                out_nodes = filter.process(in_fragments, current_env);
            }
            else if (in_nodes.Count > 0)
            {
                out_nodes = filter.process(in_nodes, current_env);
            }

            FilterState next = getNextState();

            if (next != null)
            {
                if (out_nodes.Count > 0)
                {
                    if (next is NodeFilterState)
                    {
                        NodeFilterState state = (NodeFilterState)next;
                        state.push(out_nodes);
                    }
                    else if (next is CollectionFilterState)
                    {
                        CollectionFilterState state = (CollectionFilterState)next;
                        state.push(out_nodes);
                    }

                    out_nodes.Clear();
                    result = next.traverse(current_env);
                }
                else
                {
                    result.set(FilterStateResult.Status.STATUS_NODATA, filter);
                }
            }

            in_features.Clear();
            in_fragments.Clear();
            in_nodes.Clear();

            return(result);
        }
예제 #17
0
        public override FeatureList process(FeatureList input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            foreach (Feature feature in input)
            {
                //engine.run(script, feature, null);
                if (feature.row[attributeName].ToString().ToLowerInvariant() == attributeValue)
                {
                    output.Add(feature);
                }
            }
            return(output);
        }
예제 #18
0
        /**
         * Processes a single fragment into a collection of nodes.
         *
         * @param input
         *      Individual fragment to process
         * @param env
         *      Contextual compilation environment
         * @return
         *      Resulting node list
         */
        public virtual AttributedNodeList process(Fragment input, FilterEnv env)
        {
#if TODO
            AttributedNodeList output;
            osg.Geode          geode = new osg.Geode();
            foreach (Drawable i in input.getDrawables())
            {
                geode.addDrawable(i);
            }
            output.Add(new AttributedNode(geode));
            return(output);
#endif
            throw new NotImplementedException();
        }
예제 #19
0
        /**
         * Instructs this state's Filter to process its input.
         *
         * @param env
         *      Runtime processing environment
         */
        public override FilterStateResult traverse(FilterEnv in_env)
        {
            FilterStateResult result = new FilterStateResult();

            // clone a new environment:
            current_env = in_env.advance();

            FeatureList output = filter.process(in_features, current_env);

            FilterState next = getNextState();

            if (next != null)
            {
                if (output.Count > 0)
                {
                    if (next is FeatureFilterState)
                    {
                        FeatureFilterState state = (FeatureFilterState)next;
                        state.push(output);
                    }
                    else if (next is FragmentFilterState)
                    {
                        FragmentFilterState state = (FragmentFilterState)next;
                        state.push(output);
                    }
                    else if (next is NodeFilterState)
                    {
                        NodeFilterState state = (NodeFilterState)next;
                        state.push(output);
                    }
                    else if (next is CollectionFilterState)
                    {
                        CollectionFilterState state = (CollectionFilterState)next;
                        state.push(output);
                    }

                    result = next.traverse(current_env);
                }
                else
                {
                    result.set(FilterStateResult.Status.STATUS_NODATA, filter);
                }
            }

            // clean up
            in_features.Clear();

            return(result);
        }
예제 #20
0
 protected void applyFragmentName(Fragment frag, Feature feature, FilterEnv env)
 {
     if (getFeatureNameScript() != null)
     {
         ScriptResult r = env.getScriptEngine().run(getFeatureNameScript(), feature, env);
         if (r.isValid())
         {
             frag.setName(r.asString());
         }
         else
         {
             env.getReport().error(r.asString());
         }
     }
 }
예제 #21
0
        static GeoPoint clampToTerrain(GeoPoint input, FilterEnv env)
        {
#if TODO
            if (env.getTerrainNode() != null)
            {
                return(GeomUtil.clampToTerrain(input, env.getTerrainNode(), env.getTerrainSRS(), env.getTerrainReadCallback()));
            }
            else
            {
                return(input);
            }
            //if ( env.getTerrainNode() )
            //{
            //    osg.ref_ptr<osgUtil.LineSegmentIntersector> isector;

            //    if ( input.getSRS().isGeocentric() )
            //    {
            //        osg.Vec3d vec = input;
            //        vec.normalize();
            //        isector = new osgUtil.LineSegmentIntersector(
            //            vec * input.getSRS().getEllipsoid().getSemiMajorAxis() * 1.2,
            //            osg.Vec3d(0,0,0) );
            //    }
            //    else
            //    {
            //        osg.Vec3d p = input;
            //        osg.Vec3d vec(0,0,1);
            //        isector = new osgUtil.LineSegmentIntersector(
            //            p + vec * 1e7,
            //            p - vec * 1e7 );
            //    }

            //    RelaxedIntersectionVisitor iv;
            //    iv.setIntersector( isector.get() );
            //    iv.setReadCallback( env.getTerrainReadCallback() );
            //
            //    env.getTerrainNode().accept( iv );
            //    if ( isector.containsIntersections() )
            //    {
            //        return GeoPoint(
            //            isector.getFirstIntersection().getWorldIntersectPoint(),
            //            input.getSRS() );
            //    }
            //}
            //return input;
#endif
            throw new NotImplementedException();
        }
예제 #22
0
        override public FeatureList process(Feature input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            //resolve the xlate shortcut
            Mogre.Matrix4 workingMatrix = Matrix;

            //TODO: this can go into process (FeatureList) instead of running for every feature..
            if (TranslateScript != null)
            {
                ScriptResult r = env.getScriptEngine().run(TranslateScript, input, env);
                if (r.isValid())
                {
                    workingMatrix.MakeTrans(new Mogre.Vector3((float)r.asVec3().x, (float)r.asVec3().y, (float)r.asVec3().z));
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }
            if (workingSrs != null || (workingMatrix != null && workingMatrix != Mogre.Matrix4.IDENTITY))
            {
                //TODO foreach (Geometry shape in input.getGeometry())
                //{
                //    if (workingMatrix != null && !workingMatrix.Equals(Mogre.Matrix4.IDENTITY))
                //    {

                //        XformVisitor visitor = new XformVisitor();
                //        visitor.mat = workingMatrix;
                //        shape.accept(visitor);
                //    }
                //    if (workingSrs != null && !(workingSrs.equivalentTo(env.getInputSRS())))
                //    {
                //        workingSrs.transformInPlace(shape);
                //    }
                //}
                if (workingSrs != null && !(workingSrs.equivalentTo(env.getInputSRS())))
                {
                    Geometry temp = GeometryTransform.TransformGeometry(input.getGeometry(), ((SharpMapSpatialReference)workingSrs).MathTransform);
                    input.setGeometry(temp);
                    //workingSrs.transformInPlace(input.getGeometry());
                }
            }
            output.Add(input);
            return(output);
        }
예제 #23
0
        /**
         * Copy constructor.
         */
        public FilterEnv(FilterEnv rhs)
        {
            session        = rhs.session;
            feature_extent = rhs.feature_extent;
            cell_extent    = rhs.cell_extent;
            in_srs         = rhs.in_srs;
            out_srs        = rhs.out_srs;
            terrain_node   = rhs.terrain_node;
            terrain_srs    = rhs.terrain_srs;
#if TODO
            terrain_read_cb = rhs.terrain_read_cb.get();
#endif
            script_engine   = rhs.script_engine;
            properties      = rhs.properties;
            optimizer_hints = rhs.optimizer_hints;
            resource_cache  = rhs.resource_cache;
            report          = rhs.report;
        }
예제 #24
0
        protected virtual Vector4D getColorForFeature(Feature input, FilterEnv env)
        {
            Vector4D result = overall_color;

            if (is_batch)
            {
                result = batch_feature_color;
            }
            else if (getColorScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getColorScript(), input, env);
                if (r.isValid())
                {
                    result = r.asVec4();
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            return(result);
        }
        public ScriptResult run(Script script, Feature feature, FilterEnv env)
        {
            if (!string.IsNullOrWhiteSpace(script.Language) &&
                !script.Language.ToLowerInvariant().Contains("python"))
            {
                return(new ScriptResult(script.Code));
            }

            scope.SetVariable("feature", feature);
            scope.SetVariable("env", env);

            StringBuilder code = new StringBuilder();

            foreach (Script sc in scripts)
            {
                code.Append(sc.Code);
            }
            code.Append(script.Code);

            ScriptSource source2 = engine.CreateScriptSourceFromString(code.ToString(), SourceCodeKind.AutoDetect);
            var          res2    = source2.Execute(scope);

            return(new ScriptResult(res2));
        }
예제 #26
0
 // FeatureFilter overrides
 public FeatureList process(Feature input, FilterEnv env);
예제 #27
0
        protected void applyOverlayTexturing(osg.Geometry geom, Feature input, FilterEnv env)
        {
            GeoExtent tex_extent;

            if (getRasterOverlayScript() != null)
            {
                // if there's a raster script for this filter, we're applying textures per-feature:
                tex_extent = new GeoExtent(
                    input.getExtent().getSouthwest().getAbsolute(),
                    input.getExtent().getNortheast().getAbsolute());
            }
            else
            {
                // otherwise prepare the geometry for an overlay texture covering the entire working extent:
                tex_extent = env.getExtent();
            }

            float width  = (float)tex_extent.getWidth();
            float height = (float)tex_extent.getHeight();

            // now visit the verts and calculate texture coordinates for each one.
            osg.Vec3Array verts = (osg.Vec3Array)(geom.getVertexArray());
            if (verts != null)
            {
                // if we are dealing with geocentric data, we will need to xform back to a real
                // projection in order to determine texture coords:
                GeoExtent tex_extent_geo;
                if (env.getInputSRS().isGeocentric())
                {
                    tex_extent_geo = new GeoExtent(
                        tex_extent.getSRS().getGeographicSRS().transform(tex_extent.getSouthwest()),
                        tex_extent.getSRS().getGeographicSRS().transform(tex_extent.getNortheast()));
                }

                osg.Vec2Array texcoords = new osg.Vec2Array(verts.size());
                for (int j = 0; j < verts.size(); j++)
                {
                    // xform back to raw SRS w.o. ref frame:
                    GeoPoint vert = new GeoPoint(verts[j], env.getInputSRS());
                    GeoPoint vert_map = vert.getAbsolute();
                    float    tu, tv;
                    if (env.getInputSRS().isGeocentric())
                    {
                        tex_extent_geo.getSRS().transformInPlace(vert_map);
                        tu = (vert_map.X - tex_extent_geo.getXMin()) / width;
                        tv = (vert_map.Y - tex_extent_geo.getYMin()) / height;
                    }
                    else
                    {
                        tu = (vert_map.X - tex_extent.getXMin()) / width;
                        tv = (vert_map.Y - tex_extent.getYMin()) / height;
                    }
                    (*texcoords)[j].set(tu, tv);
                }
                geom.setTexCoordArray(0, texcoords);
            }

            // if we are applying the raster per-feature, do so now.
            // TODO: deprecate? will we ever use this versus the BuildNodesFilter overlay? maybe
            if (getRasterOverlayScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getRasterOverlayScript(), input, env);
                if (r.isValid())
                {
                    RasterResource raster = env.getSession().getResources().getRaster(r.asString());
                    if (raster != null)
                    {
                        Image            image = null;
                        std.stringstream builder;
                        builder << "rtex_" << input.getOID() << ".jpg"; //TODO: dds with DXT1 compression

                        osg.StateSet raster_ss = new osg.StateSet();
                        if (raster.applyToStateSet(raster_ss.get(), tex_extent, getRasterOverlayMaxSize(), out image))
                        {
                            image.setFileName(builder.str());
                            geom.setStateSet(raster_ss.get());

                            // add this as a skin resource so the compiler can properly localize and deploy it.
                            env.getResourceCache().addSkin(raster_ss.get());
                        }
                    }
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }
        }
예제 #28
0
        public override FragmentList process(Feature input, FilterEnv env)
        {
            FragmentList output;

            // LIMITATION: this filter assumes all feature's shapes are the same
            // shape type! TODO: sort into bins of shape type and create a separate
            // geometry for each. Then merge the geometries.
            bool needs_tessellation = false;

            Fragment frag = new Fragment();

            GeoShapeList shapes = input.getShapes();

#if TODO
            // if we're in batch mode, the color was resolved in the other process() function.
            // otherwise we still need to resolve it.
            Vector4D color = getColorForFeature(input, env);
#endif
#if TODO
            foreach (GeoShape s in shapes)
            {
                GeoShape shape = s;

                if (shape.getShapeType() == GeoShape.ShapeType.TYPE_POLYGON)
                {
                    needs_tessellation = true;
                }


                osg.Geometry geom = new osg.Geometry();

                // TODO: pre-total points and pre-allocate these arrays:
                osg.Vec3Array verts = new osg.Vec3Array();
                geom.setVertexArray(verts);
                uint vert_ptr = 0;

                // per-vertex coloring takes more memory than per-primitive-set coloring,
                // but it renders faster.
                osg.Vec4Array colors = new osg.Vec4Array();
                geom.setColorArray(colors);
                geom.setColorBinding(osg.Geometry.BIND_PER_VERTEX);

                //osg.Vec3Array* normals = new osg.Vec3Array();
                //geom.setNormalArray( normals );
                //geom.setNormalBinding( osg.Geometry.BIND_OVERALL );
                //normals.push_back( osg.Vec3( 0, 0, 1 ) );


                Mogre.PixelFormat prim_type =
                    shape.getShapeType() == GeoShape.ShapeType.TYPE_POINT ? osg.PrimitiveSet.POINTS :
                    shape.getShapeType() == GeoShape.ShapeType.TYPE_LINE ? osg.PrimitiveSet.LINE_STRIP :
                    osg.PrimitiveSet.LINE_LOOP;
#endif
#if TODO
            for (int pi = 0; pi < shape.getPartCount(); pi++)
            {
                int          part_ptr = vert_ptr;
                GeoPointList points   = shape.getPart(pi);
                for (int vi = 0; vi < points.Count; vi++)
                {
                    verts.Add(points[vi]);
                    vert_ptr++;
                    colors.Add(color);
                }
                geom.addPrimitiveSet(new osg.DrawArrays(prim_type, part_ptr, vert_ptr - part_ptr));
            }

            // tessellate all polygon geometries. Tessellating each geometry separately
            // with TESS_TYPE_GEOMETRY is much faster than doing the whole bunch together
            // using TESS_TYPE_DRAWABLE.
            if (needs_tessellation)
            {
                osgUtil.Tessellator tess;
                tess.setTessellationType(osgUtil.Tessellator.TESS_TYPE_GEOMETRY);
                tess.setWindingType(osgUtil.Tessellator.TESS_WINDING_POSITIVE);
                tess.retessellatePolygons(*geom);

                applyOverlayTexturing(geom, input, env);
            }

            generateNormals(geom);

            frag.addDrawable(geom);
        }

        frag.addAttributes(input.getAttributes());
        applyFragmentName(frag, input, env);

        output.Add(frag);

        return(output);
#endif
            throw new NotImplementedException();
        }
예제 #29
0
        // FragmentFilter overrides
        public override FragmentList process(FeatureList input, FilterEnv env)
        {
            FragmentList output = new FragmentList();

            //cuidado con las entidades dentro del for

            int     i = 0;
            Vector3 scale;
            Vector3 distanceScale;
            Vector3 mScale = new Vector3(1, 1, 1);
            float   lWidth = 1;

            if (Scale != null)
            {
                scale = Registry.instance().GetEngine("Python").run(Scale).asVec3();
            }
            else
            {
                scale = new Vector3(1, 1, 1);
            }

            if (CoordScale != null)
            {
                distanceScale = Registry.instance().GetEngine("Python").run(CoordScale).asVec3();
            }
            else
            {
                distanceScale = new Vector3(1, 1, 1);
            }
            if (LineWidth != null)
            {
                lWidth = Registry.instance().GetEngine("Python").run(LineWidth).asFloat();
            }
            if (MaterialScale != null)
            {
                mScale = Registry.instance().GetEngine("Python").run(MaterialScale).asVec3();
            }

            SceneNode nodeIni = point3d(env.getName(), i, 0, 0, 0, null, env.getSceneMgr());

#if ESCALA_NODO_INICIAL
            if (Scale != null)
            {
                nodeIni.SetScale(Registry.instance().GetEngine("Python").run(Scale).asVec3());
            }
            if (coordScale != null)
            {
                Vector3 vec3 = Registry.instance().GetEngine("Python").run(Scale).asVec3();
                nodeIni.SetPosition(nodeIni.Position.x * vec3.x, nodeIni.Position.y * vec3.y, nodeIni.Position.z * vec3.z);
#if TRACE_BUILDGEOMFILTER
                System.Console.WriteLine("(" + n.Position.x + "," + n.Position.y + ")");
#endif
            }
#endif
            Fragment fIni = new Fragment(nodeIni);
            output.Add(fIni);

            foreach (Feature feature in input)
            {
                //if type of features is Point
                if (feature.row.Geometry is SharpMap.Geometries.Point)
                {
                    SharpMap.Geometries.Point p = (SharpMap.Geometries.Point)feature.row.Geometry;

                    i++;
                    SceneNode n = point3d(env.getName(), i, (float)p.X, (float)p.Y, 0, nodeIni, env.getSceneMgr());

                    n.SetScale(scale);
                    n.SetPosition(n.Position.x * distanceScale.x, n.Position.y * distanceScale.y, n.Position.z * distanceScale.z);

                    Fragment f = new Fragment(n);
                    output.Add(f);
                }

                //if type of features is Polygon
                else if (feature.row.Geometry is SharpMap.Geometries.Polygon)
                {
                    SharpMap.Geometries.Polygon polygon = (SharpMap.Geometries.Polygon)feature.row.Geometry;

                    ManualObject polygonNode = null;

                    if (polygonNode == null)
                    {
                        polygonNode = env.getSceneMgr().CreateManualObject(env.getName() + "Node_" + i);
                        MaterialPtr material = MaterialManager.Singleton.Create("Test/ColourPolygon",
                                                                                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                        material.GetTechnique(0).GetPass(0).VertexColourTracking =
                            (int)TrackVertexColourEnum.TVC_AMBIENT;

                        //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                        MogreTessellationCallbacks callback = new MogreTessellationCallbacks(polygonNode, Color, feature);

                        if (nameMaterial != null)
                        {
                            callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                            callback.MaterialScale = mScale;
                        }

                        GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                        Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                        Glu.gluTessBeginPolygon(null);
                        Glu.gluTessBeginContour();

                        int        numVertices = polygon.ExteriorRing.NumPoints /*/10+1*/;
                        int        numValores  = 3;
                        double[][] data        = new double[numVertices][];

                        for (int j = 0; j < numVertices; j++)
                        {
                            data[j] = new double[numValores];
                        }

                        int k = 0;
                        //1 polygon = N vertices
                        foreach (SharpMap.Geometries.Point point in polygon.ExteriorRing.Vertices)
                        {
                            //if (k % 10 == 0)
                            {
                                data[k /*/10*/][0] = point.X;
                                data[k /*/10*/][1] = point.Y;
                                data[k /*/10*/][2] = 0;
                            }
                            k++;

                            //SceneNode n = point3d(env.getName()+i+k, k + 10, (float)point.X * 10.0f, (float)point.Y * 10.0f, 0, nodeIni, env.getSceneMgr());
                        }
                        for (int j = 0; j < data.GetLength(0); j++)
                        {
                            Glu.gluTessVertex(data[j], 0, new Vector3((float)(data[j][1] * distanceScale.y), (float)(data[j][2] * distanceScale.z), (float)(data[j][0] * distanceScale.x)));
                        }

                        Glu.gluTessEndContour();
                        Glu.gluTessNormal(0, 0, 1);
                        Glu.gluTessEndPolygon();

                        nodeIni.AttachObject(polygonNode);
                    }
                    i++;
                }

                //if type of features is MultiPolygon
                else if (feature.row.Geometry is SharpMap.Geometries.MultiPolygon)
                {
                    SharpMap.Geometries.MultiPolygon mp = (SharpMap.Geometries.MultiPolygon)feature.row.Geometry;

                    // 1 MultiPolygon = N polygon
                    foreach (SharpMap.Geometries.Polygon polygon in mp.Polygons)
                    {
                        ManualObject polygonNode = null;

                        if (polygonNode == null)
                        {
                            polygonNode = env.getSceneMgr().CreateManualObject(env.getName() + "Node_" + i);
                            MaterialPtr material = MaterialManager.Singleton.Create("Test/ColourPolygon",
                                                                                    ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                            material.GetTechnique(0).GetPass(0).VertexColourTracking =
                                (int)TrackVertexColourEnum.TVC_AMBIENT;


                            //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                            MogreTessellationCallbacks callback = new MogreTessellationCallbacks(polygonNode, Color, feature);

                            if (nameMaterial != null)
                            {
                                callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                                callback.MaterialScale = mScale;
                            }

                            GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                            Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                            Glu.gluTessBeginPolygon(null);
                            Glu.gluTessBeginContour();

                            int        numVertices = polygon.ExteriorRing.NumPoints;
                            int        numValores  = 3;
                            double[][] data        = new double[numVertices][];

                            for (int j = 0; j < numVertices; j++)
                            {
                                data[j] = new double[numValores];
                            }

                            int k = 0;
                            //1 polygon = N vertices
                            foreach (SharpMap.Geometries.Point point in polygon.ExteriorRing.Vertices)
                            {
                                data[k][0] = point.X;
                                data[k][1] = point.Y;
                                data[k][2] = 0;

                                k++;

                                //SceneNode n = point3d(env.getName(), i, (float)point.X, (float)point.Y, 0, nodeIni, env.getSceneMgr());
                            }
                            for (int j = 0; j < data.GetLength(0); j++)
                            {
                                Glu.gluTessVertex(data[j], 0, new Vector3(((float)data[j][1]) * distanceScale.y, ((float)data[j][2]) * distanceScale.z, ((float)data[j][0]) * distanceScale.x));
                            }

                            Glu.gluTessEndContour();
                            Glu.gluTessNormal(0, 0, 1);
                            Glu.gluTessEndPolygon();

                            nodeIni.AttachObject(polygonNode);
                        }
                        i++;
                    }
                }

                //if type of features is Line
                else if (feature.row.Geometry is SharpMap.Geometries.ILineal /*SharpMap.Geometries.LineString*/)
                {
                    System.Collections.Generic.List <SharpMap.Geometries.ILineal> lineas = new System.Collections.Generic.List <SharpMap.Geometries.ILineal>();
                    if (feature.row.Geometry is SharpMap.Geometries.MultiLineString)
                    {
                        foreach (SharpMap.Geometries.LineString l in ((SharpMap.Geometries.MultiLineString)(feature.row.Geometry)).LineStrings)
                        {
                            lineas.Add(l);
                        }
                    }
                    else
                    {
                        lineas.Add((SharpMap.Geometries.ILineal)(feature.row.Geometry));
                    }
                    foreach (SharpMap.Geometries.ILineal line in lineas)
                    {
                        ManualObject lineNode = env.getSceneMgr().CreateManualObject("line" + i);

                        //MaterialPtr material = MaterialManager.Singleton.Create(nameMaterial,
                        //ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                        //material.GetTechnique(0).GetPass(0).VertexColourTracking =
                        //               (int)TrackVertexColourEnum.TVC_AMBIENT;
                        //material.GetTechnique(0).GetPass(0).SetDepthBias(100);
                        //material.GetTechnique(0).GetPass(0).LightingEnabled = false;

                        int nSeg = 5; // Number of segments on the cap or join pieces
                        BufferParameters         param           = new BufferParameters(nSeg, BufferParameters.BufferEndCapStyle.CapRound, BufferParameters.BufferJoinStyle.JoinRound, 2);
                        IGeometryFactory <Coord> geometryFactory = new GeometryFactory <Coord>(new CoordSeqFac(new CoordFac(PrecisionModelType.DoubleFloating)));
                        //IWktGeometryReader<Coord> reader = geometryFactory.WktReader;
                        //string txt = feature.row.Geometry.AsText();
                        ILineString         line1       = (ILineString)GeometryConverter.ToNTSGeometry((SharpMap.Geometries.LineString)line, geometryFactory); // (ILineString<Coord>)reader.Read(txt);
                        IGeometry           coordBuffer = line1.Buffer(lWidth, param);
                        ICoordinateSequence coords      = coordBuffer.Coordinates;
                        //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                        MogreTessellationCallbacks callback = new MogreTessellationCallbacks(lineNode, Color, feature);
                        if (nameMaterial != null)
                        {
                            callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                            callback.MaterialScale = mScale;
                        }

                        GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                        Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                        Glu.gluTessBeginPolygon(null);
                        Glu.gluTessBeginContour();
                        foreach (Coord coord in coords)
                        {
                            double[] data = new double[] { coord.X *distanceScale.x, coord.Y *distanceScale.y, (double.IsNaN(coord.Z) ? 0 : coord.Z) * distanceScale.z };

                            Glu.gluTessVertex(data, 0, new Vector3((float)data[1], (float)data[2], (float)data[0]));
                        }
                        Glu.gluTessEndContour();
                        Glu.gluTessNormal(0, 0, 1);
                        Glu.gluTessEndPolygon();
                        i++;
                        nodeIni.AttachObject(lineNode);
                    }
                    if ((feature.row.Geometry is SharpMap.Geometries.Polygon) | (feature.row.Geometry is SharpMap.Geometries.MultiPolygon))
                    {
                        Fragment f = new Fragment(nodeIni);
                        output.Add(f);
                    }
                }
            }
            i = 0;//breakpoint

            /*foreach (Fragment fragment in output)
             * {
             *  fragment.Node.Scale(0,0,0);
             * }*/

#if TODO
            // if features are arriving in batch, resolve the color here.
            // otherwise we will resolve it later in process(feature,env).
            is_batch            = input.Count > 1;
            batch_feature_color = overall_color;
            if (is_batch && getColorScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getColorScript(), env);
                if (r.isValid())
                {
                    batch_feature_color = r.asVec4();
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            return(base.process(input, env));
#endif
            //throw new NotImplementedException();

            if (successor != null)
            {
                if (successor is FeatureFilter)
                {
                    FeatureFilter filter = (FeatureFilter)successor;
                    FeatureList   l      = filter.process(input, env);
                    //FeatureList l = successor.process(input, env);
                }
                else if (successor is FragmentFilter)
                {
                    FragmentFilter filter = (FragmentFilter)successor;
                    FragmentList   l      = filter.process(output, env);
                }
            }

            return(output);
        }
예제 #30
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            MogreApp.setLocations(prj.getMogreLocations());
            SetupMogre();
            Mogre.SceneManager sm = app.SceneManager;

            foreach (MogreGis.FilterGraph graph in prj.getFilterGraphs())
            {

                foreach (osgGISProjects.Source source in prj.getSources())
                {
                    if (Path.GetExtension(source.getURI()) != ".shp")
                    {
                        throw new NotImplementedException();
                    }

                    if (source.getName() == graph.getName())
                    {
                        MogreGis.FilterEnv env = null;
                        MogreGis.FeatureList featureList = null;

                        FeatureDataSet ds = new FeatureDataSet();
                        source.DataSource.Open();
                        source.DataSource.ExecuteIntersectionQuery(source.DataSource.GetExtents(), ds);
                        source.DataSource.Close();
                        FeatureDataTable features = (FeatureDataTable)ds.Tables[0];
                        featureList = MogreGis.Feature.DataTableToList(features);

                        foreach (Script script in prj.getScripts())
                        {
                            Registry.instance().GetEngine("Python").run(script);
                        }

                        foreach (Feature feature in featureList)
                        {
                            SharpMapSpatialReferenceFactory smsrf = new SharpMapSpatialReferenceFactory();
                            ShapeFile shp = new ShapeFile(source.getURI());
                            shp.Open();
                            SharpMapSpatialReference sr;
                            sr = (SharpMapSpatialReference)smsrf.createSRSfromWKT(shp.CoordinateSystem.WKT);
                            feature.getGeometry().SpatialReference = sr;
                        }

                        env = new MogreGis.FilterEnv(sm, "env" + graph.getName());
                        env.setScriptEngine(Registry.instance().GetEngine("Python"));
                        foreach (MogreGis.Filter filter in graph.getFilters())
                        {
                            if (filter is MogreGis.FragmentFilter)
                            {
                                (filter as MogreGis.FragmentFilter).process(featureList, env);
                            }
                            if (filter is MogreGis.FeatureFilter)
                            {
                                featureList = (filter as MogreGis.FeatureFilter).process(featureList, env);
                            }
                        }
                    }
                }
            }
            app.getRoot().StartRendering();
        }
예제 #31
0
        /**
         * Gets an exact copy of this instance.
         *
         * @return Exact copy of the FilterEnv
         */
        public FilterEnv clone()
        {
            FilterEnv a = new FilterEnv(this);

            return(a);
        }