using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SOASystem.Data.GeoDataClient;
using SOASystem.Data.GeoDataTypes;
using SOASystem.Data.FileGDBClient;
using SOASystem.Data;
namespace FileGDBProviderTest
{
class Editing
{
public static bool TestEditing()
{
FileGDBConnection conn = new FileGDBConnection(@"database=C:\FileGDBProvider\data\Editing.gdb");
conn.Open();
// Open the cities tables
//
FileGDBCommand cmd = new FileGDBCommand("Select * from cities", conn);
FileGDBDataAdapter adp = new FileGDBDataAdapter(cmd);
GeoDataSet ds = new GeoDataSet();
adp.Fill(ds);
GeoDataFeatureClass fc = ds.FeatureClasses.get_Item(0);
GeoDataFeature cabazonRow = fc.NewFeature();
cabazonRow["AREANAME"] = new GeoDataString("Cabazon");
cabazonRow["CLASS"] = new GeoDataString("town");
cabazonRow["POP2000"] = 2939;
Point Pt = new Point();
Pt.X = -116.78443;
Pt.Y = 33.919902;
fc.Features.Add(cabazonRow);
// Using the builder creates the necessary commands on the adapter to
// apply the edits
//
FileGDBCommandBuilder builder = new FileGDBCommandBuilder(adp);
adp.Update(fc);
// Search and Update
//
Proxies.SpatialReference sr = fc.SpatialRef;
double gridSize = fc.GridSize;
GeoDataFeatureClass fc2 = new GeoDataFeatureClass("Cities", sr, gridSize);
cmd.CommandText = "Select * from cities where AREANAME='Apple Valley'";
adp.Fill(fc2);
foreach (GeoDataFeature fe in fc2.Features)
fe["CLASS"] = new GeoDataString("city");
adp.Update(fc2);
fc2.Features.Clear();
fc2.AcceptChanges();
// Apply delete to a set of features located within an envelope.
//
double XMin = -117.4,
YMin = 33.65,
XMax = -116.8,
YMax = 33.86;
Envelope env = new Envelope(XMin, YMax, XMax - XMin, YMax - YMin);
GeoDataSpatialParameter geoP = new GeoDataSpatialParameter()
{
SourceColumn = "Shape",
SpatialRelType = SpatialRelType.SpatialRelContains,
GeoDataType = GeoDataType.Geometry,
Value = env
};
cmd.CommandText = "Select * from Cities";
cmd.Parameters.Add(geoP);
adp.Fill(fc2);
foreach (GeoDataFeature fi in fc2.Features)
fi.Delete();
adp.Update(fc2);
return true;
}
}
}