Edit shape file in web MapServer application

Paolo Corti pcorti at GMAIL.COM
Tue Aug 1 07:12:15 EDT 2006


Hello
I developed a simple application to edit shapefile with mapscript

this is the sample code to add a point with some attributes to a point
shapefile (c#):

private void AddPoint(Double x, Double y, String activeLayer, String[,]
fieldValues)
		{
			//check: this action is valid only for point shapefiles
			pointObj point = pixel2point(new pointObj(x,y,0,0)); //conver the image
point in map point
			String shapeFullPath = map.shapepath + "\\" + activeLayer + ".shp";
			shapefileObj shapefile = new shapefileObj(shapeFullPath,-2);
			if(shapefile.type!=(int)mapscript.MS_SHAPEFILE_POINT)
			{
				//notify action
				lblInfo.Text = "This action can be performed only on point shapefiles.";
			}
			else
			{
				/*Alternative way to insert a point in the shapefile using shapeObj:
				//create line to store point
				lineObj line = new lineObj();
				line.add(point);
				//create shape
				shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT);
				shape.add(line);
				//add shape to shapefile
				shapefile.add(shape;
				*/
				shapefile.addPoint(point);
				//add record for dbf table
				OleDbConnection cn = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
map.shapepath + ";Extended Properties=dBASE IV;User ID=Admin;Password=");
				cn.Open();
				OleDbCommand com = cn.CreateCommand();
				//get field list and value list
				String fieldList = "";
				String valueList = "";
				for(int i=0; i<(fieldValues.Length/2); i++)
				{
					fieldList = fieldList + fieldValues[i,0];
					valueList = valueList + "'" + fieldValues[i,1] + "'";
					if(i<((fieldValues.Length/2)-1))
					{
						fieldList = fieldList + ", ";
						valueList = valueList + ", ";
					}
				}
				com.CommandText = "INSERT INTO " + activeLayer + " (" + fieldList + ")
VALUES(" + valueList + ")";
				com.CommandType = CommandType.Text;
				com.ExecuteNonQuery();
				cn.Close();
				//notify action
				lblInfo.Text = "Point added (" + shapefile.numshapes.ToString() + "
features in shapefile).";
			}
			shapefile.Dispose();
		}

This is what I want to ask here, as I am new to mapscript and MapServer: is
it safe to edit shapefile online, can be any thread or cuncurrency issues?
At least in my ESRI experience with ArcIMS I know that they don't let you
edit a shapefile if it is served on the web (ArcIMS locks it). If you need
to edit data you need ArcSDE.
So it is strange to me that MapServer give you this edit possibilites, but
maybe (I couldn't find anywhere) is it safe to use this capacities only for
standalone apps?
Or should i convert my data to MySQL or PostGIS?

thank you
Paolo
-- 
View this message in context: http://www.nabble.com/Edit-shape-file-in-web-MapServer-application-tf2032930.html#a5592464
Sent from the Mapserver - User forum at Nabble.com.



More information about the mapserver-users mailing list