Esempio n. 1
0
        override public FeatureList process(FeatureList input, FilterEnv env)
        {
            //first time through, establish a working SRS for output data.
            if (workingSrs == null)
            {
                //first try to use the terrain SRS if so directed:
                SpatialReference newOutSrs = UseTerrainSrs ? env.getTerrainSRS() : null;
                if (newOutSrs == null)
                {
                    //failing that, see if we have an SRS in a resource:
                    if (Srs == null && SrsScript != null)
                    {
                        //Console.WriteLine("Borrame" + SrsScript.getCode());
                        Srs = env.getSession().Resources.getSRS(SrsScript.getCode());
#if TODO_PH
                        ScriptResult r = env.getScriptEngine().run(SrsScript, env);
                        if (r.isValid())
                        {
                            Srs = (env.getSession().Resources.getSRS(r.asString()));

                            throw new NotImplementedException();
                        }
                        else
                        {
                            env.getReport().error(r.asString());
                        }
#endif
                    }
                    newOutSrs = Srs;
                }
                //set the "working" SRS that will be used for all features passing though this filter:
                workingSrs = newOutSrs != null ? newOutSrs : env.getInputSRS();

                //LOCALIZE points arround a local origin (the working extent's centroid)
                if (workingSrs != null && Localize)
                {
                    if (env.getCellExtent().getSRS().isGeographic() && env.getCellExtent().getWidth() > 179)
                    {
                        //NOP - no localization for big geog extent ... needs more thought perhaps
                    }
                    else
                    {
                        GeoPoint centroid0 = newOutSrs == null?
                                             newOutSrs.transform(env.getCellExtent()).getCentroid()
                                                 : env.getCellExtent().getCentroid();

                        //we do want the localizer point on the surface if possible:
                        GeoPoint centroid = ClampToTerrain(centroid0, env);
                        if (centroid == null)
                        {
                            centroid = centroid0;
                        }

                        Mogre.Matrix4 localizer = new Mogre.Matrix4();
                        //For geocentric datasets, we need a special localizer matrix:
                        if (workingSrs.isGeocentric())
                        {
                            localizer = workingSrs.getEllipsoid().createGeocentricInvRefFrame(centroid);
                            localizer = localizer.Inverse();
                        }
                        //For projected datasets, just a simple translation
                        else
                        {
                            localizer.SetTrans(new Mogre.Vector3((float)centroid.X, (float)centroid.Y, (float)0.0));
                        }
                        workingSrs = workingSrs.cloneWithNewReferenceFrame(localizer);
                    }
                }
            }
            //we have to assing the output SRS on each pass
            if (workingSrs != null)
            {
                env.setOutputSRS(workingSrs);
            }
            return(base.process(input, env));
        }
        override public FeatureList process(FeatureList input, FilterEnv env)
        {
            //first time through, establish a working SRS for output data.
            if (workingSrs == null)
            {
                //first try to use the terrain SRS if so directed:
                SpatialReference newOutSrs = UseTerrainSrs ? env.getTerrainSRS() : null;
                if (newOutSrs == null)
                {
                    //failing that, see if we have an SRS in a resource:
                    if (Srs == null && SrsScript != null)
                    {
                        //Console.WriteLine("Borrame" + SrsScript.getCode());
                        Srs = env.getSession().Resources.getSRS(SrsScript.getCode());
#if TODO_PH
                        ScriptResult r = env.getScriptEngine().run(SrsScript, env);
                        if (r.isValid())
                        {

                            Srs = (env.getSession().Resources.getSRS(r.asString()));

                            throw new NotImplementedException();

                    }
                        else
                        {
                            env.getReport().error(r.asString());
                        }
#endif
                    }
                    newOutSrs = Srs;
                }
                //set the "working" SRS that will be used for all features passing though this filter:
                workingSrs = newOutSrs != null ? newOutSrs : env.getInputSRS();

                //LOCALIZE points arround a local origin (the working extent's centroid)
                if (workingSrs != null && Localize)
                {
                    if (env.getCellExtent().getSRS().isGeographic() && env.getCellExtent().getWidth() > 179)
                    {
                        //NOP - no localization for big geog extent ... needs more thought perhaps
                    }
                    else
                    {
                        GeoPoint centroid0 = newOutSrs == null ?
                            newOutSrs.transform(env.getCellExtent()).getCentroid()
                            : env.getCellExtent().getCentroid();
                        //we do want the localizer point on the surface if possible:
                        GeoPoint centroid = ClampToTerrain(centroid0, env);
                        if (centroid == null)
                        {
                            centroid = centroid0;
                        }

                        Mogre.Matrix4 localizer = new Mogre.Matrix4();
                        //For geocentric datasets, we need a special localizer matrix:
                        if (workingSrs.isGeocentric())
                        {
                            localizer = workingSrs.getEllipsoid().createGeocentricInvRefFrame(centroid);
                            localizer = localizer.Inverse();
                        }
                        //For projected datasets, just a simple translation
                        else
                        {
                            localizer.SetTrans(new Mogre.Vector3((float)centroid.X, (float)centroid.Y, (float)0.0));
                        }
                        workingSrs = workingSrs.cloneWithNewReferenceFrame(localizer);
                    }
                }
            }
            //we have to assing the output SRS on each pass
            if (workingSrs != null)
            {
                env.setOutputSRS(workingSrs);
            }
            return base.process(input, env);
        }