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)); }
public override FeatureList process(FeatureList input, FilterEnv env) { FeatureList output = new FeatureList(); // HACER ALGO DEL ESTILO: if (transform == null) { //Create zone UTM 32N projection IProjectedCoordinateSystem utmProj = CreateUtmProjection(32); //Create geographic coordinate system (lets just reuse the CS from the projection) IGeographicCoordinateSystem geoCS = utmProj.GeographicCoordinateSystem; //Create transformation CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); // TODO DANI Mirar de donde viene este source y target ICoordinateTransformation Coordinatetransform = null;// TODO = ctFac.CreateFromCoordinateSystems(source, target); //cs string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; //ICoordinateSystem cs = SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem; ICoordinateSystem cs = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem; //wgs84 GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; //gcs CoordinateSystemFactory cFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); //CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); //Create Bessel 1840 geographic coordinate system IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); //coordsys //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", 110)); parameters.Add(new ProjectionParameter("scale_factor", 0.997)); parameters.Add(new ProjectionParameter("false_easting", 3900000)); parameters.Add(new ProjectionParameter("false_northing", 900000)); IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); Coordinatetransform = ctFac.CreateFromCoordinateSystems(gcs, coordsys);//gcsWGS84 -> gcenCsWGS84 //Apply transformation transform = Coordinatetransform.MathTransform; } SharpMap.Geometries.Point p = new SharpMap.Geometries.Point(30.0, 20.0); p = GeometryTransform.TransformPoint(p, transform); /*IMPORTANTE * foreach (Feature feature in input) * { * feature.row.Geometry = GeometryTransform.TransformGeometry(feature.row.Geometry, transform); * //feature.row.Geometry = GeometryTransform.TransformMultiPolygon(feature.row.Geometry, transform); * } * IMPORTANTE*/ foreach (Feature f in input) { output.Add(f);//output = input } // Cosas a cambiar: // Primero, la construccion del transform está siguiendo el ejemplo, pero hay que tener en cuenta los datos del xml y construirlo en consecuencia // Segundo, el filtro debe retornar una NUEVA lista, y no modificar la inicial. Ahora modifica los valores de la lista inicial // IMPORTANTE RETORNAR NUEVA LISTA OUTPUT <----------- FALTA POR HACER #if TODO // first time through, establish a working SRS for output data. if (working_srs == null) { // first try to use the terrain SRS if so directed: SpatialReference new_out_srs = getUseTerrainSRS() ? env.getTerrainSRS() : null; if (new_out_srs == null) { // failing that, see if we have an SRS in a resource: if (getSRS() == null && getSRSScript() != null) { ScriptResult r = env.getScriptEngine().run(getSRSScript(), env); if (r.isValid()) { setSRS(env.getSession().getResources().getSRS(r.ToString())); } else { env.getReport().error(r.ToString()); } } new_out_srs = srs; } // set the "working" SRS that will be used for all features passing though this filter: working_srs = new_out_srs != null ? new_out_srs : env.getInputSRS(); // LOCALIZE points around a local origin (the working extent's centroid) if (working_srs != null && getLocalize()) //&& env.getExtent().getArea() > 0.0 ) { if (env.getCellExtent().getSRS().isGeographic() && env.getCellExtent().getWidth() > 179.0) { //NOP - no localization for big geog extent ... needs more thought perhaps } else { GeoPoint centroid0 = new_out_srs != null? new_out_srs.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; } Matrixd localizer; // For geocentric datasets, we need a special localizer matrix: if (working_srs.isGeocentric()) { localizer = working_srs.getEllipsoid().createGeocentricInvRefFrame(centroid); localizer.invert(localizer); } // For projected datasets, just a simple translation: else { localizer = osg.Matrixd.translate(-centroid); } working_srs = working_srs.cloneWithNewReferenceFrame(localizer); } } } // we have to assign the output SRS on each pass if (working_srs != null) { env.setOutputSRS(working_srs); } return(base.process(input, env)); #endif //throw new NotImplementedException(); 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); }
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); }