//---------------------------------------------------------------------------------------- // �� �ܣ� ��ѯָ����Χ�ڵ�Ҫ�� // // �� �ߣ� // // // �� �ڣ�2007.05.# // //----------------------------------------------------------------------------------------- public ParcelProperty[] GetNearParcels(string parcelType, GeocodeAddress geocodeAddress, double bufferDistance) { ParcelProperty[] parcelProperties = null; //���ڵ�ַ���� ���ε�͵�Ļ������������Σ� MgGeometryFactory geoFactory = new MgGeometryFactory(); MgCoordinate coord = geoFactory.CreateCoordinateXY(Convert.ToDouble(geocodeAddress.lon), Convert.ToDouble(geocodeAddress.lat)); MgPoint pt = geoFactory.CreatePoint(coord); //��ѯ��ָ����Χ�ڣ�����Σ���Ҫ�� MgPolygon buffer = (MgPolygon)pt.Buffer(bufferDistance, null); MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgFeatureQueryOptions query = new MgFeatureQueryOptions(); query.SetFilter("RTYPE LIKE '" + parcelType + "%'"); query.SetSpatialFilter("SHPGEOM", buffer, MgFeatureSpatialOperations.Inside); MgResourceIdentifier resId = new MgResourceIdentifier("Library://Samples/Sheboygan/Data/Parcels.FeatureSource"); MgFeatureReader featReader = featureService.SelectFeatures(resId, "Parcels", query); //�����ѯ��� ArrayList props = new ArrayList(); while (featReader.ReadNext()) { ParcelProperty prop = new ParcelProperty(); prop.ID = featReader.GetInt32("Autogenerated_SDF_ID").ToString(); prop.Acreage = featReader.GetString("RACRE"); prop.BillingAddr = featReader.GetString("RBILAD"); prop.Description1 = featReader.GetString("RLDESCR1"); prop.Description2 = featReader.GetString("RLDESCR2"); prop.Description3 = featReader.GetString("RLDESCR3"); prop.Description4 = featReader.GetString("RLDESCR4"); prop.LotDimension = featReader.GetString("RLOT"); prop.LotSize = featReader.GetInt32("RSQFT"); prop.Owner = featReader.GetString("RNAME"); prop.Zoning = featReader.GetString("RTYPE"); props.Add(prop); } parcelProperties = (ParcelProperty[])props.ToArray(typeof(ParcelProperty)); return parcelProperties; }
//--------------------------------------------------------------------------------------- // // ���ܣ�����Ҫ�ض��� // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- public void createNewParcel(MgPolygon geom, ParcelProperty newParcel) { MgPropertyCollection properties = buildPropertyCol(newParcel); MgAgfReaderWriter agfWriter = new MgAgfReaderWriter(); MgByteReader byteReader = agfWriter.Write(geom); properties.Add(new MgGeometryProperty("SHPGEOM", byteReader)); MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgResourceIdentifier parcelSource = new MgResourceIdentifier("Library://MgTutorial/Data/Parcels.FeatureSource"); MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); commands.Add(new MgInsertFeatures("Parcels", properties)); featureService.UpdateFeatures(parcelSource, commands, false); ////////////////////////////////////////// /* MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); MgPropertyCollection properties = new MgPropertyCollection(); MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter(); MgByteReader byteReader = agfReaderWriter.Write(geometry); MgGeometryProperty geometryProperty = new MgGeometryProperty("SHPGEOM",byteReader); properties.Add(new MgInt32Property("RSQFT", 322)); properties.Add(new MgStringProperty("RNAME", "YourName")); properties.Add(new MgStringProperty("RTYPE", "GFC")); MgPropertyCollection properties = new MgPropertyCollection (); properties.Add(geometryProperty); MgInsertFeatures insertCommand = new MgInsertFeatures(className, properties); commands.Add(insertCommand); featureService.UpdateFeatures(featureSource, commands, false); * */ }
//--------------------------------------------------------------------------------------- // // ���ܣ�����Ҫ�����ݣ������ڹ�����¼ // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- private MgPropertyCollection populateParcelFeatureAttributes(MgPolygon geom, ParcelProperty newParcel) { MgPropertyCollection props = new MgPropertyCollection(); MgAgfReaderWriter agfWriter = new MgAgfReaderWriter(); props.Add(new MgGeometryProperty("GEOM", agfWriter.Write(geom))); props.Add(new MgStringProperty("ACRE", newParcel.Acreage)); props.Add(new MgStringProperty("BILLADDR", newParcel.BillingAddr)); props.Add(new MgStringProperty("DESC1", newParcel.Description1)); props.Add(new MgStringProperty("DESC2", newParcel.Description2)); props.Add(new MgStringProperty("DESC3", newParcel.Description3)); props.Add(new MgStringProperty("DESC4", newParcel.Description4)); props.Add(new MgStringProperty("LOTDIM", newParcel.LotDimension)); props.Add(new MgInt32Property("SQFT", newParcel.LotSize)); props.Add(new MgStringProperty("OWNER", newParcel.Owner)); props.Add(new MgStringProperty("ZONE", newParcel.Zoning)); return props; }
private MgPropertyCollection buildPropertyCol(ParcelProperty newFeatureValue) { MgPropertyCollection props = new MgPropertyCollection(); props.Add(new MgStringProperty("RACRE", newFeatureValue.Acreage)); props.Add(new MgStringProperty("RBILAD", newFeatureValue.BillingAddr)); props.Add(new MgStringProperty("RLDESCR1", newFeatureValue.Description1)); props.Add(new MgStringProperty("RLDESCR2", newFeatureValue.Description2)); props.Add(new MgStringProperty("RLDESCR3", newFeatureValue.Description3)); props.Add(new MgStringProperty("RLDESCR4", newFeatureValue.Description4)); props.Add(new MgStringProperty("RLOT", newFeatureValue.LotDimension)); props.Add(new MgInt32Property("RSQFT", newFeatureValue.LotSize)); props.Add(new MgStringProperty("RNAME", newFeatureValue.Owner)); props.Add(new MgStringProperty("RTYPE", newFeatureValue.Zoning)); return props; }
//--------------------------------------------------------------------------------------- // // ���ܣ�����Ҫ�ض��� // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- public bool UpdateFeature(ParcelProperty newFeatureValue) { MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgFeatureService featService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgFeatureQueryOptions query = new MgFeatureQueryOptions(); string filterString = "Autogenerated_SDF_ID = " + newFeatureValue.ID; query.SetFilter(filterString); MgResourceIdentifier resId = new MgResourceIdentifier("Library://MgTutorial/Data/Parcels.FeatureSource"); MgFeatureReader featureReader = featService.SelectFeatures(resId, "Parcels", query); if (featureReader.ReadNext()) { featureReader.Close(); MgPropertyCollection properties = buildPropertyCol(newFeatureValue); MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); commands.Add(new MgUpdateFeatures("SHP_Schema:Parcels", properties, filterString)); featService.UpdateFeatures(resId, commands, false); return true; } featureReader.Close(); return false; }
public ParcelProperty GetFirstSelectedFeature() { MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgFeatureService featService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgMap map = new MgMap(); map.Open(resService, "Sheboygan"); MgSelection mapSelection = new MgSelection(map); mapSelection.Open(resService, "Sheboygan"); MgReadOnlyLayerCollection layers = mapSelection.GetLayers(); if (layers == null) return null; ParcelProperty prop = new ParcelProperty(); for (int i = 0; i < layers.GetCount(); i++) { MgLayer layer = layers.GetItem(i); if ((layer != null) && (layer.GetName() == "Parcels")) { String layerClassName = layer.GetFeatureClassName(); String selectString = mapSelection.GenerateFilter(layer, layerClassName); String layerFeatureIdString = layer.GetFeatureSourceId(); MgResourceIdentifier layerResId = new MgResourceIdentifier(layerFeatureIdString); MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions(); queryOptions.SetFilter(selectString); MgFeatureReader featReader = featService.SelectFeatures(layerResId, layerClassName, queryOptions); if (featReader.ReadNext()) { prop.ID = featReader.GetInt32("Autogenerated_SDF_ID"); prop.Acreage = featReader.GetString("RACRE"); prop.BillingAddr = featReader.GetString("RBILAD"); prop.Description1 = featReader.GetString("RLDESCR1"); prop.Description2 = featReader.GetString("RLDESCR2"); prop.Description3 = featReader.GetString("RLDESCR3"); prop.Description4 = featReader.GetString("RLDESCR4"); prop.LotDimension = featReader.GetString("RLOT"); prop.LotSize = featReader.GetInt32("RSQFT"); prop.Owner = featReader.GetString("RNAME"); prop.Zoning = featReader.GetString("RTYPE"); featReader.Close(); return prop; } featReader.Close(); } } return null; }
//--------------------------------------------------------------------------------------- // // ���ܣ�����һ����ΪtempParcel����ʱ�� // // ���ߣ� // // ���ڣ� 2007.5.23 // // ����ʷ���� // //--------------------------------------------------------------------------------------- public void createTempParcels(MgPolygon geom, ParcelProperty newParcel, string sessionId) { MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); // ��ȡ��ͼ���� MgMap map = new MgMap(); map.Open(resService, "Sheboygan"); // ������ʱ�� MgResourceIdentifier tempLayerSourceId = new MgResourceIdentifier("Session:" + sessionId + "//tempParcel.FeatureSource"); MgLayer tempParcelLayer = getLayerByName(map, "TempParcels"); if (tempParcelLayer == null) { createTempParcelFeatureSource(featureService, tempLayerSourceId); tempParcelLayer = createTempParcelLayer(resService, tempLayerSourceId, sessionId); map.GetLayers().Insert(0, tempParcelLayer); } //��Ҫ��Դ�в���Ҫ������ MgPropertyCollection props = populateParcelFeatureAttributes(geom, newParcel); MgFeatureCommandCollection commands = new MgFeatureCommandCollection(); commands.Add(new MgInsertFeatures("tempParcel", props)); featureService.UpdateFeatures(tempLayerSourceId, commands, false); tempParcelLayer.SetVisible(true); tempParcelLayer.ForceRefresh(); map.Save(resService); }