/** * Constructs a new extent. * * @param sw Southwest corner * @param ne Northeast corner * @param srs Spatial reference system */ public GeoExtent(GeoPoint _sw, GeoPoint _ne, SpatialReference _sr) { is_valid = false; is_infinite = false; if (_sw != null && _sw.getSRS() != null && _ne != null && _ne.getSRS() != null && _sr != null) { sw = _sr.transform(_sw); ne = _sr.transform(_ne); if (sw.isValid() && ne.isValid()) { is_valid = true; recalc(); } } }
/** * Creates a new geocentric SRS based on the user-supplied * geographic basic SRS. * * @param basis * Geographic SRS upon which to base the new geocentric SRS * @param reference_frame * Reference frame to apply to points in this SRS * @return * A spatial reference. Caller is responsible for deleting * the return object. */ public SpatialReference createGeocentricSRS(SpatialReference basis, Mogre.Matrix4 reference_frame) { throw new NotImplementedException(); }
public SpatialReference getOutputSRS(Session session, SpatialReference terrain_srs) { if (!grid_valid || output_srs == null) { if (levels.Count > 0 && levels[0].getFilterGraph() != null) { FilterEnv env = session.createFilterEnv(); env.setTerrainSRS(terrain_srs); FilterList filters = levels[0].getFilterGraph().getFilters(); for (int ind = filters.Count-1; ind >= 0; ind--) //reverse iterator? { if (output_srs != null) break; Filter i = filters[ind]; if (i is TransformFilter) { TransformFilter xf = (TransformFilter)i; if (xf.getUseTerrainSRS()) { if (env.getTerrainSRS() != null) { this.output_srs = env.getTerrainSRS(); } } else if (xf.getSRS()) { this.output_srs = (SpatialReference)(xf.getSRS()); } else if (xf.getSRSScript()) { ScriptResult r = env.getScriptEngine().run(xf.getSRSScript(), env); if (r.isValid()) this.output_srs = session.getResources().getSRS(r.asString()); else env.getReport().error(r.asString()); } } } if (output_srs == null) // no reproject..assume input srs { this.output_srs = levels[0].getFeatureLayer().getSRS(); } } } return output_srs; }
/** * Examines an SRS and if broken, attempts to repair it so that it works. * * @param validateSRS * SRS to repair if necessary * @return * A spatial reference. Caller is responsible for deleting * the return object. */ public SpatialReference validateSRS(SpatialReference srs_to_validate) { throw new NotImplementedException(); }
/** * Creates a new geocentric SRS based on the user-supplied * geographic basic SRS. * * @param basis * Geographic SRS upon which to base the new geocentric SRS * @return * A spatial reference. Caller is responsible for deleting * the return object. */ public SpatialReference createGeocentricSRS(SpatialReference basis) { throw new NotImplementedException(); }
// properties /** * Sets the spatial reference object in this resource. * * @param value * SRS to set */ public void setSRS(SpatialReference value) { srs = value; }
/** * Gets whether two spatial references are mathematically equivalent. * * @param lhs * First spatial reference * @param rhs * Second spatial reference * @return * True if they are mathematically equivalent. */ public static bool equivalent(SpatialReference lhs, SpatialReference rhs) { if (lhs == rhs) return true; if (lhs == null || rhs == null) return false; return lhs.equivalentTo(rhs); }
/*** Statics ********************************************************/ static bool getTerrainData(Terrain terrain, out osg.Node out_terrain_node, out SpatialReference out_terrain_srs, out GeoExtent out_terrain_extent) { if (terrain != null) { if (!string.IsNullOrEmpty(terrain.getURI())) { out_terrain_node = osgDB.readNodeFile(terrain.getAbsoluteURI()); } // first check for an explicity defined SRS: out_terrain_srs = terrain.getExplicitSRS(); if (out_terrain_srs != null && out_terrain_srs.isGeographic()) { // and make it geocentric if necessary.. out_terrain_srs = Registry.SRSFactory().createGeocentricSRS(out_terrain_srs.get()); } if (out_terrain_node != null) { // if the SRS wasn't explicit, try to read it from the scene graph: if (out_terrain_srs == null) { out_terrain_srs = Registry.SRSFactory().createSRSfromTerrain(out_terrain_node.get()); } //osgGIS.notice() // << "Loaded TERRAIN from \"" << terrain.getAbsoluteURI() << "\", SRS = " // << (out_terrain_srs != null? out_terrain_srs.getName() : "unknown") // << std.endl; } else if (!string.IsNullOrEmpty(terrain.getURI())) { //osgGIS.warn() // << "Unable to load data for terrain \"" // << terrain.getName() << "\"." // << std.endl; return false; } } out_terrain_extent = new GeoExtent(-180, -90, 180, 90, Registry.instance().getSRSFactory().createWGS84()); return true; }
public override bool equivalentTo(SpatialReference rhs) { //return this.WKT == rhs.WKT; throw new NotImplementedException(); }
/** * Sets a spatial reference for the data in this feature layer. * This method DOES NOT reproject the data in the layer. It only assigns * a spatial reference to use (in the case where the feature store does * not provide one). * * @param srs * Spatial reference system to set */ public void setSRS(SpatialReference _srs) { assigned_srs = _srs; }
/** * Sets the spatial reference system into which to reproject feature geodata. * * @param srs * Target spatial reference system. */ public void setSRS(SpatialReference _srs) { srs = _srs; }
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); }
protected virtual AttributedNodeList process(AttributedNodeList input, FilterEnv env) { Node result; if (input.Count > 1) { result = new osg.Group(); for (AttributedNodeList.iterator i = input.begin(); i != input.end(); i++) { osg.Node node = i.get().getNode(); if (node != null) { if (getEmbedAttributes()) { embedAttributes(node, i.get().getAttributes()); } result.asGroup().addChild(node); } } } else if (input.Count == 1) { result = input[0].getNode(); if (getEmbedAttributes()) { embedAttributes(result.get(), input[0].getAttributes()); } } else { return(new AttributedNodeList()); } // if there are no drawables or external refs, toss it. if (!GeomUtils.hasDrawables(result.get())) { return(AttributedNodeList()); } // NEXT create a XFORM if there's a localization matrix in the SRS. This will // prevent jittering due to loss of precision. SpatialReference input_srs = env.getInputSRS(); if (env.getExtent().getArea() > 0 && !input_srs.getReferenceFrame().isIdentity()) { Vector3D centroid = new Vector3D(0, 0, 0); osg.Matrixd irf = input_srs.getInverseReferenceFrame(); osg.Vec3d centroid_abs = centroid * irf; osg.MatrixTransform xform = new osg.MatrixTransform(irf); xform.addChild(result); result = xform; if (getApplyClusterCulling() && input_srs.isGeocentric()) { Vector3D normal = centroid_abs; normal.normalize(); //osg.BoundingSphere bs = result.computeBound(); // force it // radius = distance from centroid inside which to disable CC altogether: //float radius = bs.radius(); //osg.Vec3d control_point = bs.center(); Vector3D control_point = centroid_abs; GeoPoint env_cen = input_srs.transform(env.getCellExtent().getCentroid()); GeoPoint env_sw = input_srs.transform(env.getCellExtent().getSouthwest()); float radius = (env_cen - env_sw).length(); // dot product: 0 = orthogonal to normal, -1 = equal to normal float deviation = -radius / input_srs.getEllipsoid().getSemiMinorAxis(); osg.ClusterCullingCallback ccc = new osg.ClusterCullingCallback(); ccc.set(control_point, normal, deviation, radius); osg.Group cull_group = new osg.Group(); cull_group.setCullCallback(ccc); cull_group.addChild(xform); result = cull_group; //osgGIS.notify(osg.NOTICE) << "CCC: radius = " << radius << ", deviation = " << deviation << std.endl; //if ( getDrawClusterCullingNormals() == true ) //{ // //DRAW CLUSTER-CULLING NORMALS // osg.Geode* geode = new osg.Geode(); // osg.Geometry* g = new osg.Geometry(); // osg.Vec3Array* v = new osg.Vec3Array(2); // (*v)[0] = control_point; (*v)[1] = control_point + (normal*radius); // g.setVertexArray( v ); // osg.Vec4Array* c = new osg.Vec4Array(1); // (*c)[0] = osg.Vec4f( 0,1,0,1 ); // g.setColorArray( c ); // g.setColorBinding( osg.Geometry.BIND_OVERALL ); // g.addPrimitiveSet( new osg.DrawArrays( osg.PrimitiveSet.LINES, 0, 2 ) ); // geode.addDrawable( g ); // cull_group.addChild( geode ); //} } } if (getCullBackfaces()) { result.getOrCreateStateSet().setAttributeAndModes(new osg.CullFace(), osg.StateAttribute.ON); } if (getDisableLighting()) { result.getOrCreateStateSet().setMode(GL_LIGHTING, osg.StateAttribute.OFF); } if (getLineWidth() > 0.0f) { result.getOrCreateStateSet().setAttribute(new osg.LineWidth(line_width), osg.StateAttribute.ON); } if (getPointSize() > 0.0f) { osg.Point point = new osg.Point(); point.setSize(point_size); result.getOrCreateStateSet().setAttribute(point, osg.StateAttribute.ON); } if (getAlphaBlending()) { osg.BlendFunc blend_func = new osg.BlendFunc(); //blend_func.setFunction( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); result.getOrCreateStateSet().setAttributeAndModes(blend_func, osg.StateAttribute.ON); result.getOrCreateStateSet().setRenderingHint(osg.StateSet.TRANSPARENT_BIN); } if (getRasterOverlayScript()) { ScriptResult r = env.getScriptEngine().run(getRasterOverlayScript(), env); if (r.isValid()) { RasterResource *raster = env.getSession().getResources().getRaster(r.asString()); if (raster) { osg.Image *image = NULL; std.stringstream builder; string cell_id = env.getProperties().getValue("compiler.cell_id", ""); if (cell_id.length() > 0) { builder << "r" << cell_id << ".jpg"; } else { double x = env.getExtent().getCentroid().x(); double y = env.getExtent().getCentroid().y(); builder << std.setprecision(10) << "r" << x << "x" << y << ".jpg"; } if (raster.applyToStateSet(result.getOrCreateStateSet(), env.getExtent(), getRasterOverlayMaxSize(), &image)) { // Add this as a skin resource so the compiler can properly localize and deploy it. image.setFileName(builder.str()); env.getResourceCache().addSkin(result.getOrCreateStateSet()); } } } else { env.getReport().error(r.asString()); } } if (getOptimize()) { //osgGIS.notice() << "[BuildNodes] Optimizing..." << std.endl; osgUtil.Optimizer opt; int opt_mask = osgUtil.Optimizer.DEFAULT_OPTIMIZATIONS | osgUtil.Optimizer.MERGE_GEODES | osgUtil.Optimizer.TRISTRIP_GEOMETRY | osgUtil.Optimizer.SPATIALIZE_GROUPS; // disable texture atlases, since they mess with our shared skin resources and // don't work correctly during multi-threaded building opt_mask &= ~osgUtil.Optimizer.TEXTURE_ATLAS_BUILDER; // I've seen this crash the app when dealing with certain ProxyNodes. // TODO: investigate this later. opt_mask &= ~osgUtil.Optimizer.REMOVE_REDUNDANT_NODES; // integrate the optimizer hints: opt_mask |= env.getOptimizerHints().getIncludedOptions(); opt_mask &= ~(env.getOptimizerHints().getExcludedOptions()); opt.optimize(result.get(), opt_mask); GeometryCleaner cleaner; cleaner.clean(result.get()); } AttributedNodeList output; output.push_back(new AttributedNode(result.get())); return(output); }
/** * Constructs a new extent. * * @param xmin West edge off bounding rectangle * @param ymin South edge of bounding rectangle * @param xmax East edge of boundinng rectangle * @param ymax North edge of bounding rectangle */ public GeoExtent(double xmin, double ymin, double xmax, double ymax, SpatialReference _srs) { is_infinite = false; sw = new GeoPoint(xmin, ymin, _srs); ne = new GeoPoint(xmax, ymax, _srs); is_valid = sw != null && ne != null && _srs != null; recalc(); }
/** * Gets whether this and other SRS are mathematically equivalent. * * @param rhs * Spatial reference to compare to this one */ public abstract bool equivalentTo(SpatialReference rhs);
/** * Sets the reference terrain against which to compile. */ //public void setTerrain( // osg.Node terrain, // SpatialReference terrain_srs =NULL, // GeoExtent terrain_extent =GeoExtent.infinite() ) public void setTerrain(osg.Node _terrain, SpatialReference _terrain_srs, GeoExtent _terrain_extent) { terrain_node = _terrain; terrain_srs = (SpatialReference)_terrain_srs; terrain_extent = _terrain_extent; if (terrain_srs == null) terrain_srs = MogreGis.Registry.SRSFactory().createSRSfromTerrain(terrain_node.get()); //if ( !terrain_srs.valid() ) // osgGIS.warn() << "[MapLayerCompiler] WARNING: cannot determine SRS of terrain!" << std.endl; }
/** * Creates a new feature store and returns a handle. * * @param uri * Location at which to create the feature store. * @param shape_type * Type of shapes in this feature store. * @param schema * Attribute schema for features in this store. * * @return * Connection to the new feature store. The caller is responsible * for deleting the return object. */ public abstract FeatureStore createFeatureStore(string uri, GeoShape.ShapeType type, AttributeSchemaList schema, int dimensionality, SpatialReference srs, Properties props);