postgis 中的问题

 在将shapefile数据导入postgis1.5中,导入polygon时,当getNumPoints大于2000(大概,没仔细统计过),postgis中geometry显示为空值,在admin中,郁闷很久。附部分代码,

source = shpDataStore.getFeatureSource("world");
			FilterFactory2 filterFactory2 = CommonFactoryFinder.getFilterFactory2(null);
			FeatureCollection collection = source.getFeatures(filterFactory2.not(CQL.toFilter("NAME like ''")));
			// FeatureCollection collection = source.getFeatures();
			System.out.println(collection.size());
			// Transaction transaction = new DefaultTransaction();
			FeatureWriter featureWriter = dataStore.getFeatureWriter("province",
					Transaction.AUTO_COMMIT);

			try {
				for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
					SimpleFeature feature = (SimpleFeature) iterator.next();
					System.out.println(feature.getAttribute("NAME"));
					SimpleFeature newFeature = featureWriter.next();
					newFeature.setAttribute(0, feature.getAttribute("NAME"));
					newFeature.setAttribute(1, "中国");
					Object geometry = feature.getDefaultGeometry();
					if (geometry instanceof MultiPolygon) {
						MultiPolygon multiPolygon = (MultiPolygon) geometry;
						Polygon polygon = null;
						int i = 0;
						while (polygon == null && i <= multiPolygon.getNumGeometries()) {
							polygon = (Polygon) multiPolygon.getGeometryN(i);
							i++;
						}
						if (polygon != null) {
							int pointCount = polygon.getNumPoints();
							System.out.println(i + " polygon:" + polygon.getNumPoints());
							System.out.println(pointCount / 1000);
							newFeature.setAttribute(2, polygon);
							System.out.println("第一个");
						}
					}
					featureWriter.write();
				}
				// transaction.commit();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				// transaction.close();
				featureWriter.close();
			}
 

 

 

结果还是reference找到答案

PostGIS 1.5.1 Manual 写道
3.11.

I did an ST_AsEWKT and ST_AsText on my rather large geometry and it returned blank field. What gives?


You are probably using PgAdmin or some other tool that doesn't output large text. If your geometry is big enough, it will appear blank in these tools. Use PSQL if you really need to see it or output it in WKT.


--To check number of geometries are really blank
SELECT count(gid) FROM geotable WHERE the_geom IS NULL;
 

你可能感兴趣的:(open,webgis)