Index: org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/CrsFactory.java =================================================================== --- org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/CrsFactory.java (revisione 740) +++ org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/CrsFactory.java (copia locale) @@ -308,17 +308,22 @@ SpatialReference sr = new SpatialReference(); Vector vector = new Vector(); vector.add(value); - sr.ImportFromESRI(vector); - sr.Fixup(); try { + sr.ImportFromESRI(vector); + sr.Fixup(); + } catch (Exception e) { + logger.debug("Can't import from ESRI WKT.", e); + return null; + } + try { sr.AutoIdentifyEPSG(); String authorityCode = sr.GetAuthorityCode(null); if (!StringUtils.isEmpty(authorityCode)) { - //logger.info("AuthorityCode: " + authorityCode); + logger.debug("AuthorityCode: " + authorityCode); return new Crs(sr); } } catch (Exception e) { - //logger.info("Can't AutoIdentifyEPSG.", e); + logger.debug("Can't AutoIdentifyEPSG.", e); } boolean bProj4; try { @@ -326,7 +331,7 @@ String proj4 = sr.ExportToProj4(); bProj4 = true; } catch (Exception e2) { - //logger.info("Can't ExportToProj4.", e2); + logger.debug("Can't ExportToProj4.", e2); bProj4 = false; } int code; @@ -336,6 +341,9 @@ code = identifyESRI(sr); if (code == -1) { code = identifyEPSG(sr, false); + if (code == 0) { + return null; + } } } } catch (SQLException e3) { @@ -389,6 +397,7 @@ String sql = "SELECT coord_ref_sys_code FROM EPSG_COORDINATEREFERENCESYSTEM WHERE coord_ref_sys_kind = '" + kind + "' AND REPLACE(REPLACE(LOWER(coord_ref_sys_name),' / ',' '),'-',' ') LIKE '%" + normalizeESRI(source_sr_name) + "%' AND deprecated = 0"; + logger.debug(sql); ResultSet result = Query.select(sql, conn.getConnection()); @@ -395,20 +404,21 @@ while (result.next()) { int code = result.getInt("coord_ref_sys_code"); try { - //logger.info("Trying to match EPSG:{}...", code); + logger.debug("Trying to match EPSG:{}...", code); SpatialReference target_sr = new SpatialReference(); target_sr.ImportFromEPSG(code); target_sr.MorphToESRI(); if (bProj4) { + sr.MorphToESRI(); String source_proj4 = sr.ExportToProj4(); - //logger.info("Source proj4: {}", source_proj4); + logger.debug("Source proj4: {}", source_proj4); String target_proj4 = target_sr.ExportToProj4(); - //logger.info("Target proj4: {}", target_proj4); + logger.debug("Target proj4: {}", target_proj4); if (StringUtils.equals(source_proj4, target_proj4)) { String target_sr_name = target_sr.GetAttrValue(attr); dist = StringUtils.getLevenshteinDistance(normalizeESRI(source_sr_name), normalizeESRI(target_sr_name)); if (dist == 0) { - //logger.info("EPSG:{} matches!", code); + logger.debug("EPSG:{} matches!", code); return code; } } @@ -416,7 +426,7 @@ String target_sr_name = target_sr.GetAttrValue(attr); dist = StringUtils.getLevenshteinDistance(normalizeESRI(source_sr_name), normalizeESRI(target_sr_name)); if (dist == 0) { - //logger.info("EPSG:{} matches!", code); + logger.debug("EPSG:{} matches!", code); return code; } } @@ -425,16 +435,16 @@ best_code = code; } } catch (Exception e) { - //logger.info("Can't ImportFromEPSG.", e); + logger.debug("Can't ImportFromEPSG.", e); } } - /*if (best_code > 0) { // && best_dist <= 5 - logger.info("EPSG:{} is the best match (dist={})!", best_code, best_dist); - } else { + if (best_code > 0) { // && best_dist <= 5 + logger.debug("EPSG:{} is the best match (Levenshtein Distance = {}).", best_code, best_dist); + } /*else { //best_code = 0; - logger.info("No EPSG code matches!"); + logger.debug("No EPSG code matches!"); }*/ return best_code; } @@ -456,6 +466,7 @@ + " AND ESRI_PROJ LIKE '" + sr.GetAttrValue("PROJCS") + "'"; } } + logger.debug(sql); ResultSet result = Query.select(sql, conn.getConnection()); @@ -462,7 +473,7 @@ while (result.next()) { int code = result.getInt("ESRI_CODE"); String wkt = result.getString("ESRI_WKT"); - //logger.info("Trying to match ESRI:{}...", code); + logger.debug("Trying to match ESRI:{}...", code); try { SpatialReference target_sr = new SpatialReference(); target_sr.ImportFromWkt(wkt); @@ -471,16 +482,16 @@ String target_proj4 = target_sr.ExportToProj4(); if (StringUtils.equals(source_proj4, target_proj4)) { conn.close(); - //logger.info("ESRI:{} matches!", code); + logger.debug("ESRI:{} matches!", code); return code; } } catch (Exception e) { - //logger.info("gvSIG can't identify the ESRI code..."); + logger.debug("gvSIG can't identify the ESRI code..."); } } conn.close(); - //logger.info("gvSIG can't identify the ESRI code..."); + logger.debug("gvSIG can't identify the ESRI code..."); return code0; } @@ -487,15 +498,40 @@ public String normalizeESRI(String sr_name) { String name; name = StringUtils.replace(sr_name, "GCS_", ""); + name = StringUtils.replaceChars(name, "()", ""); name = StringUtils.replace(name, "St_", "St. "); name = StringUtils.replace(name, "WGS_19", "WGS "); // e.g. WGS_1984 --> WGS 84 name = StringUtils.replace(name, "_19", ""); // e.g. NAD_1927 --> NAD27 - name = StringUtils.replace(name, "_2000", "2000"); // e.g. NZGD_2000 --> NZGD2000 + name = StringUtils.replace(name, "_20", "20"); // e.g. ITRF_2008 --> ITRF2008 + name = StringUtils.replace(name, "_Adj_1958", "(58)"); + name = StringUtils.replace(name, "_Bern", " (Bern)"); + name = StringUtils.replace(name, "_CGQ77", "(CGQ77)"); + name = StringUtils.replace(name, "_CORS96", "(CORS96)"); + name = StringUtils.replace(name, "_CSRS", "(CSRS)"); + name = StringUtils.replace(name, "_DEF_1976", "(76)"); + name = StringUtils.replace(name, "_ED77", "(ED77)"); + name = StringUtils.replace(name, "_ft", "(ft)"); + name = StringUtils.replace(name, "_ftUS", "(ftUS)"); + name = StringUtils.replace(name, "_HARN", "(HARN)"); + name = StringUtils.replace(name, "_MA11", "(MA11)"); + name = StringUtils.replace(name, "_NSRS2007", "(NSRS2007)"); + name = StringUtils.replace(name, "_PA11", "(PA11)"); + name = StringUtils.replace(name, "_Paris", " (Paris)"); + name = StringUtils.replace(name, "_StatePlane", ""); + if (StringUtils.contains(name, "_FIPS")) name = StringUtils.split(name, "_FIPS")[0]; + if (StringUtils.endsWith(name, "_m")) name = StringUtils.replace(name, "_m", "(m)"); + + name = StringUtils.replace(name, "1870_Madrid", "1870 (Madrid)"); + name = StringUtils.replace(name, "83_2011", "83(2011)"); // e.g. NAD_1983_2011 --> NAD83(2011) + name = StringUtils.replace(name, "Ferro", "(Ferro)"); name = StringUtils.replace(name, "Hungarian_1972", "HD72"); name = StringUtils.replace(name, "Indonesian_1974", "ID74"); name = StringUtils.replace(name, "TC_1948", "TC(1948)"); name = StringUtils.replace(name, "MGI_M", "MGI Austria M"); //"MGI_M" --> "MGI / Austria M" + name = StringUtils.replace(name, "New_Brunswick_Stereographic", "New Brunswick Stereographic (ATS77)"); name = StringUtils.replace(name, "Lisboa", "Lisbon"); + name = StringUtils.replace(name, "Lisbon_Lisbon", "Lisbon (Lisbon)"); + name = StringUtils.replace(name, "Oslo_Norway", "(Oslo) NGO"); name = StringUtils.replace(name, "_", " "); name = StringUtils.lowerCase(name); return name;