Revision 28489

View differences:

trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGIS.java
46 46
import java.io.ByteArrayOutputStream;
47 47
import java.io.PrintStream;
48 48
import java.io.UnsupportedEncodingException;
49
import java.sql.SQLException;
49 50
import java.sql.Types;
50 51

  
51 52
import com.hardcode.gdbms.engine.values.NullValue;
52 53
import com.hardcode.gdbms.engine.values.Value;
53 54
import com.hardcode.gdbms.engine.values.ValueWriter;
55
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException;
56
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
57
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
54 58
import com.iver.cit.gvsig.fmap.core.FShape;
55 59
import com.iver.cit.gvsig.fmap.core.FShapeM;
56 60
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
......
65 69
import com.iver.cit.gvsig.fmap.drivers.DefaultJDBCDriver;
66 70
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
67 71
import com.iver.cit.gvsig.fmap.drivers.XTypes;
72
import com.vividsolutions.jts.geom.Geometry;
68 73

  
69 74
/**
70 75
 * @author fjp
......
230 235
	 * @param dbLayerDef
231 236
	 * @param feat
232 237
	 * @return
238
	 * @throws SQLException
239
	 * @throws ProcessVisitorException
233 240
	 */
234 241
	public String getSqlInsertFeature(DBLayerDefinition dbLayerDef,
235
			IFeature feat) {
242
			IFeature feat) throws ProcessVisitorException {
236 243
		StringBuffer sqlBuf = new StringBuffer("INSERT INTO "
237 244
				+ dbLayerDef.getComposedTableName() + " (");
238 245
		String sql = null;
......
277 284
				geometry=ShapeMFactory.createPolyline2DM(new GeneralPathX(geometry.getInternalShape()),((IGeometryM)geometry).getMs()); //MCoord
278 285
			}
279 286
		}
287
		if (!isCorrectGeometry(geometry, type))
288
			throw new ProcessVisitorException("incorrect_geometry",new Exception());
280 289
		//MCoord
281 290
		if ((type == (FShape.LINE|FShape.M)) || (type == (FShape.POINT|FShape.M))){
282 291
			sqlBuf.append(" GeometryFromText( '"
283 292
					+ ((FShapeM)geometry.getInternalShape()).toText() + "', "
284 293
					+ DefaultJDBCDriver.removePrefix(dbLayerDef.getSRID_EPSG()) + ")");
285 294
		}else{
295
			Geometry jtsGeom=geometry.toJTSGeometry();
296
			if (jtsGeom==null || !isCorrectType(jtsGeom, type)){
297
				throw new ProcessVisitorException("incorrect_geometry",new Exception());
298
			}
286 299
			sqlBuf.append(" GeometryFromText( '"
287
				+ geometry.toJTSGeometry().toText() + "', "
300
				+ jtsGeom.toText() + "', "
288 301
				+ DefaultJDBCDriver.removePrefix(dbLayerDef.getSRID_EPSG()) + ")");
289 302
		}
290 303

  
......
294 307
		return sql;
295 308
	}
296 309

  
310
	private boolean isCorrectType(Geometry jtsGeom, int type) {
311
		if (FShape.POLYGON==type){
312
			if (!jtsGeom.getGeometryType().equals("MultiPolygon") && !jtsGeom.getGeometryType().equals("Polygon") )
313
				return false;
314
		}
315
		return true;
316
	}
317

  
318
	private boolean isCorrectGeometry(IGeometry geometry, int type) {
319
		if (FShape.POLYGON==type){
320
			FPolygon2D polygon = (FPolygon2D)geometry.getInternalShape();
321
			if (!(polygon.getBounds2D().getWidth()>0 && polygon.getBounds2D().getHeight()>0))
322
				return false;
323
		}else if (FShape.LINE==type){
324
			FPolyline2D line = (FPolyline2D)geometry.getInternalShape();
325
			if (!(line.getBounds2D().getWidth()>0 || line.getBounds2D().getHeight()>0))
326
				return false;
327
		}
328

  
329
		return true;
330
	}
331

  
297 332
	public String getSqlCreateIndex(DBLayerDefinition lyrDef) {
298 333
		String indexName = lyrDef.getTableName() + "_"
299 334
				+ lyrDef.getFieldGeometry() + "_gist";
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGISWriter.java
6 6
import java.sql.Statement;
7 7
import java.sql.Types;
8 8

  
9
import javax.swing.JOptionPane;
10

  
11
import org.apache.log4j.Logger;
12

  
9 13
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException;
10 14
import com.hardcode.gdbms.driver.exceptions.WriteDriverException;
11 15
import com.hardcode.gdbms.engine.data.driver.DriverException;
16
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException;
12 17
import com.iver.cit.gvsig.exceptions.visitors.ProcessWriterVisitorException;
13 18
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException;
14 19
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException;
......
172 177
			}
173 178

  
174 179
			numRows++;
180
		}catch (ProcessVisitorException e) {
181
			Logger.getLogger(this.getClass()).error(getName(), e);
182
//			JOptionPane.showMessageDialog(null, "incorrect_geometry");
175 183
		} catch (SQLException e) {
176
			throw new ProcessWriterVisitorException(getName(),e);
184
			throw new ProcessWriterVisitorException(this.getName(),e);
177 185
		}
178 186

  
179 187
	}

Also available in: Unified diff