/** * 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); }
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); }
/** * Runs the graph to generate a feature store. The graph should only * contain FeatureFilter and CollectionFilter type filters. * * Executes the graph by passing features to the first filter in the * chain. That filter will process the data, pass the results along to * the next filter, and so on until completion. * * @param cursor * Source cursor for features to process * @param env * Contextual compilation environment * @param output_uri * URI of a feature store to create and in which to store the results * @return * A structure describing the result of the compilation. */ public FilterGraphResult computeFeatureStore(FeatureCursor cursor, FilterEnv env, string output_uri) { #if TODO bool ok = false; // first build the filter state chain, validating that there are ONLY feature filters // present. No other filter type is permitted when generating a feature store. FilterState first = null; foreach (Filter i in filter_prototypes) { Filter filter = i; if (!(filter is FeatureFilter)) { //TODO osgGIS.notify(osg.WARN) << "Error: illegal filter of type \"" << filter.getFilterType() << "\" in graph. Only feature features are allowed." << std.endl; return(FilterGraphResult.error("Illegal first filter type in filter graph")); } FilterState next_state = filter.newState(); if (first == null) { first = next_state; } else { first.appendState(next_state); } } if (first == null) { //TODO osgGIS.notify(osg.WARN) << "Error: filter graph \"" << getName() << "\" is empty." << std.endl; return(FilterGraphResult.error("Illegal: empty filter graph")); } // next, append a WriteFeatures filter that will generate the output // feature store. WriteFeaturesFilter writer = new WriteFeaturesFilter(); writer.setOutputURI(output_uri); //writer.setAppendMode( WriteFeaturesFilter.OVERWRITE ); FilterState output_state = writer.newState(); first.appendState(output_state); // now run the graph. FilterStateResult state_result; int count = 0; osg.Timer_t start = osg.Timer.instance().tick(); env.setOutputSRS(env.getInputSRS()); FeatureFilterState state = (FeatureFilterState)first; while (state_result.isOK() && cursor.hasNext()) { state.push(cursor.next()); state_result = state.traverse(env); count++; } if (state_result.isOK()) { state_result = state.signalCheckpoint(); } osg.Timer_t end = osg.Timer.instance().tick(); double dur = osg.Timer.instance().delta_s(start, end); if (state_result.isOK()) { return(FilterGraphResult.ok(output_state.getLastKnownFilterEnv())); } else { return(FilterGraphResult.error("Filter graph failed to compute feature store")); } #endif throw new NotImplementedException(); }
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)); }
/** * Runs the graph to generate a scene graph. * * Executes the graph by passing features to the first filter in the * chain. That filter will process the data, pass the results along to * the next filter, and so on until completion. * * @param cursor * Source cursor for features to process * @param env * Contextual compilation environment * @param output * Group node that, upon success, contains resulting nodes of compiled scene * as its children * @return * A structure describing the result of the compilation. */ public FilterGraphResult computeNodes(FeatureCursor cursor, FilterEnv env, osg.Group output) { FilterStateResult state_result; output = null; NodeFilterState output_state; // first build a new state chain corresponding to our filter prototype chain. FilterState first = null; foreach (Filter i in filter_prototypes) { FilterState next_state = i.newState(); if (first == null) { first = next_state; } else { first.appendState(next_state); } if (next_state is NodeFilterState) { output_state = (NodeFilterState)next_state; } } // now traverse the states. if (first != null) { int count = 0; osg.Timer_t start = osg.Timer.instance().tick(); env.setOutputSRS(env.getInputSRS()); if (first is FeatureFilterState) { FeatureFilterState state = (FeatureFilterState)first; while (state_result.isOK() && cursor.hasNext()) { state.push(wind(cursor.next())); state_result = state.traverse(env); count++; } if (state_result.isOK()) { state_result = state.signalCheckpoint(); } } else if (first is FragmentFilterState) { FragmentFilterState state = (FragmentFilterState)first; while (state_result.isOK() && cursor.hasNext()) { state.push(wind(cursor.next())); state_result = state.traverse(env); count++; } if (state_result.isOK()) { state_result = state.signalCheckpoint(); } } else if (first is CollectionFilterState) { CollectionFilterState state = (CollectionFilterState)first; while (state_result.isOK() && cursor.hasNext()) { state.push(wind(cursor.next())); state_result = state.traverse(env); count++; } if (state_result.isOK()) { state_result = state.signalCheckpoint(); } } osg.Timer_t end = osg.Timer.instance().tick(); double dur = osg.Timer.instance().delta_s(start, end); //osgGIS.notify( osg.ALWAYS ) << std.endl << "Time = " << dur << " s; Per Feature Avg = " << (dur/(double)count) << " s" << std.endl; } else { state_result.set(FilterStateResult.Status.STATUS_NODATA); } if (output_state != null && state_result.hasData()) { output = new osg.Group(); foreach (AttributedNode i in output_state.getOutput()) { output.addChild(i.getNode()); } } if (state_result.isOK()) { return(FilterGraphResult.ok(output_state.getLastKnownFilterEnv())); } else { return(FilterGraphResult.error("Filter graph failed to compute any nodes")); } }