308 |
308 |
SpatialReference sr = new SpatialReference();
|
309 |
309 |
Vector<String> vector = new Vector<String>();
|
310 |
310 |
vector.add(value);
|
311 |
|
sr.ImportFromESRI(vector);
|
312 |
|
sr.Fixup();
|
313 |
311 |
try {
|
|
312 |
sr.ImportFromESRI(vector);
|
|
313 |
sr.Fixup();
|
|
314 |
} catch (Exception e) {
|
|
315 |
logger.debug("Can't import from ESRI WKT.", e);
|
|
316 |
return null;
|
|
317 |
}
|
|
318 |
try {
|
314 |
319 |
sr.AutoIdentifyEPSG();
|
315 |
320 |
String authorityCode = sr.GetAuthorityCode(null);
|
316 |
321 |
if (!StringUtils.isEmpty(authorityCode)) {
|
317 |
|
//logger.info("AuthorityCode: " + authorityCode);
|
|
322 |
logger.debug("AuthorityCode: " + authorityCode);
|
318 |
323 |
return new Crs(sr);
|
319 |
324 |
}
|
320 |
325 |
} catch (Exception e) {
|
321 |
|
//logger.info("Can't AutoIdentifyEPSG.", e);
|
|
326 |
logger.debug("Can't AutoIdentifyEPSG.", e);
|
322 |
327 |
}
|
323 |
328 |
boolean bProj4;
|
324 |
329 |
try {
|
... | ... | |
326 |
331 |
String proj4 = sr.ExportToProj4();
|
327 |
332 |
bProj4 = true;
|
328 |
333 |
} catch (Exception e2) {
|
329 |
|
//logger.info("Can't ExportToProj4.", e2);
|
|
334 |
logger.debug("Can't ExportToProj4.", e2);
|
330 |
335 |
bProj4 = false;
|
331 |
336 |
}
|
332 |
337 |
int code;
|
... | ... | |
336 |
341 |
code = identifyESRI(sr);
|
337 |
342 |
if (code == -1) {
|
338 |
343 |
code = identifyEPSG(sr, false);
|
|
344 |
if (code == 0) {
|
|
345 |
return null;
|
|
346 |
}
|
339 |
347 |
}
|
340 |
348 |
}
|
341 |
349 |
} catch (SQLException e3) {
|
... | ... | |
389 |
397 |
String sql = "SELECT coord_ref_sys_code FROM EPSG_COORDINATEREFERENCESYSTEM WHERE coord_ref_sys_kind = '"
|
390 |
398 |
+ kind + "' AND REPLACE(REPLACE(LOWER(coord_ref_sys_name),' / ',' '),'-',' ') LIKE '%"
|
391 |
399 |
+ normalizeESRI(source_sr_name) + "%' AND deprecated = 0";
|
|
400 |
logger.debug(sql);
|
392 |
401 |
|
393 |
402 |
ResultSet result = Query.select(sql, conn.getConnection());
|
394 |
403 |
|
395 |
404 |
while (result.next()) {
|
396 |
405 |
int code = result.getInt("coord_ref_sys_code");
|
397 |
406 |
try {
|
398 |
|
//logger.info("Trying to match EPSG:{}...", code);
|
|
407 |
logger.debug("Trying to match EPSG:{}...", code);
|
399 |
408 |
SpatialReference target_sr = new SpatialReference();
|
400 |
409 |
target_sr.ImportFromEPSG(code);
|
401 |
410 |
target_sr.MorphToESRI();
|
402 |
411 |
if (bProj4) {
|
|
412 |
sr.MorphToESRI();
|
403 |
413 |
String source_proj4 = sr.ExportToProj4();
|
404 |
|
//logger.info("Source proj4: {}", source_proj4);
|
|
414 |
logger.debug("Source proj4: {}", source_proj4);
|
405 |
415 |
String target_proj4 = target_sr.ExportToProj4();
|
406 |
|
//logger.info("Target proj4: {}", target_proj4);
|
|
416 |
logger.debug("Target proj4: {}", target_proj4);
|
407 |
417 |
if (StringUtils.equals(source_proj4, target_proj4)) {
|
408 |
418 |
String target_sr_name = target_sr.GetAttrValue(attr);
|
409 |
419 |
dist = StringUtils.getLevenshteinDistance(normalizeESRI(source_sr_name), normalizeESRI(target_sr_name));
|
410 |
420 |
if (dist == 0) {
|
411 |
|
//logger.info("EPSG:{} matches!", code);
|
|
421 |
logger.debug("EPSG:{} matches!", code);
|
412 |
422 |
return code;
|
413 |
423 |
}
|
414 |
424 |
}
|
... | ... | |
416 |
426 |
String target_sr_name = target_sr.GetAttrValue(attr);
|
417 |
427 |
dist = StringUtils.getLevenshteinDistance(normalizeESRI(source_sr_name), normalizeESRI(target_sr_name));
|
418 |
428 |
if (dist == 0) {
|
419 |
|
//logger.info("EPSG:{} matches!", code);
|
|
429 |
logger.debug("EPSG:{} matches!", code);
|
420 |
430 |
return code;
|
421 |
431 |
}
|
422 |
432 |
}
|
... | ... | |
425 |
435 |
best_code = code;
|
426 |
436 |
}
|
427 |
437 |
} catch (Exception e) {
|
428 |
|
//logger.info("Can't ImportFromEPSG.", e);
|
|
438 |
logger.debug("Can't ImportFromEPSG.", e);
|
429 |
439 |
}
|
430 |
440 |
|
431 |
441 |
}
|
432 |
442 |
|
433 |
|
/*if (best_code > 0) { // && best_dist <= 5
|
434 |
|
logger.info("EPSG:{} is the best match (dist={})!", best_code, best_dist);
|
435 |
|
} else {
|
|
443 |
if (best_code > 0) { // && best_dist <= 5
|
|
444 |
logger.debug("EPSG:{} is the best match (Levenshtein Distance = {}).", best_code, best_dist);
|
|
445 |
} /*else {
|
436 |
446 |
//best_code = 0;
|
437 |
|
logger.info("No EPSG code matches!");
|
|
447 |
logger.debug("No EPSG code matches!");
|
438 |
448 |
}*/
|
439 |
449 |
return best_code;
|
440 |
450 |
}
|
... | ... | |
456 |
466 |
+ " AND ESRI_PROJ LIKE '" + sr.GetAttrValue("PROJCS") + "'";
|
457 |
467 |
}
|
458 |
468 |
}
|
|
469 |
logger.debug(sql);
|
459 |
470 |
|
460 |
471 |
ResultSet result = Query.select(sql, conn.getConnection());
|
461 |
472 |
|
462 |
473 |
while (result.next()) {
|
463 |
474 |
int code = result.getInt("ESRI_CODE");
|
464 |
475 |
String wkt = result.getString("ESRI_WKT");
|
465 |
|
//logger.info("Trying to match ESRI:{}...", code);
|
|
476 |
logger.debug("Trying to match ESRI:{}...", code);
|
466 |
477 |
try {
|
467 |
478 |
SpatialReference target_sr = new SpatialReference();
|
468 |
479 |
target_sr.ImportFromWkt(wkt);
|
... | ... | |
471 |
482 |
String target_proj4 = target_sr.ExportToProj4();
|
472 |
483 |
if (StringUtils.equals(source_proj4, target_proj4)) {
|
473 |
484 |
conn.close();
|
474 |
|
//logger.info("ESRI:{} matches!", code);
|
|
485 |
logger.debug("ESRI:{} matches!", code);
|
475 |
486 |
return code;
|
476 |
487 |
}
|
477 |
488 |
} catch (Exception e) {
|
478 |
|
//logger.info("gvSIG can't identify the ESRI code...");
|
|
489 |
logger.debug("gvSIG can't identify the ESRI code...");
|
479 |
490 |
}
|
480 |
491 |
}
|
481 |
492 |
|
482 |
493 |
conn.close();
|
483 |
|
//logger.info("gvSIG can't identify the ESRI code...");
|
|
494 |
logger.debug("gvSIG can't identify the ESRI code...");
|
484 |
495 |
return code0;
|
485 |
496 |
}
|
486 |
497 |
|
487 |
498 |
public String normalizeESRI(String sr_name) {
|
488 |
499 |
String name;
|
489 |
500 |
name = StringUtils.replace(sr_name, "GCS_", "");
|
|
501 |
name = StringUtils.replaceChars(name, "()", "");
|
490 |
502 |
name = StringUtils.replace(name, "St_", "St. ");
|
491 |
503 |
name = StringUtils.replace(name, "WGS_19", "WGS "); // e.g. WGS_1984 --> WGS 84
|
492 |
504 |
name = StringUtils.replace(name, "_19", ""); // e.g. NAD_1927 --> NAD27
|
493 |
|
name = StringUtils.replace(name, "_2000", "2000"); // e.g. NZGD_2000 --> NZGD2000
|
|
505 |
name = StringUtils.replace(name, "_20", "20"); // e.g. ITRF_2008 --> ITRF2008
|
|
506 |
name = StringUtils.replace(name, "_Adj_1958", "(58)");
|
|
507 |
name = StringUtils.replace(name, "_Bern", " (Bern)");
|
|
508 |
name = StringUtils.replace(name, "_CGQ77", "(CGQ77)");
|
|
509 |
name = StringUtils.replace(name, "_CORS96", "(CORS96)");
|
|
510 |
name = StringUtils.replace(name, "_CSRS", "(CSRS)");
|
|
511 |
name = StringUtils.replace(name, "_DEF_1976", "(76)");
|
|
512 |
name = StringUtils.replace(name, "_ED77", "(ED77)");
|
|
513 |
name = StringUtils.replace(name, "_ft", "(ft)");
|
|
514 |
name = StringUtils.replace(name, "_ftUS", "(ftUS)");
|
|
515 |
name = StringUtils.replace(name, "_HARN", "(HARN)");
|
|
516 |
name = StringUtils.replace(name, "_MA11", "(MA11)");
|
|
517 |
name = StringUtils.replace(name, "_NSRS2007", "(NSRS2007)");
|
|
518 |
name = StringUtils.replace(name, "_PA11", "(PA11)");
|
|
519 |
name = StringUtils.replace(name, "_Paris", " (Paris)");
|
|
520 |
name = StringUtils.replace(name, "_StatePlane", "");
|
|
521 |
if (StringUtils.contains(name, "_FIPS")) name = StringUtils.split(name, "_FIPS")[0];
|
|
522 |
if (StringUtils.endsWith(name, "_m")) name = StringUtils.replace(name, "_m", "(m)");
|
|
523 |
|
|
524 |
name = StringUtils.replace(name, "1870_Madrid", "1870 (Madrid)");
|
|
525 |
name = StringUtils.replace(name, "83_2011", "83(2011)"); // e.g. NAD_1983_2011 --> NAD83(2011)
|
|
526 |
name = StringUtils.replace(name, "Ferro", "(Ferro)");
|
494 |
527 |
name = StringUtils.replace(name, "Hungarian_1972", "HD72");
|
495 |
528 |
name = StringUtils.replace(name, "Indonesian_1974", "ID74");
|
496 |
529 |
name = StringUtils.replace(name, "TC_1948", "TC(1948)");
|
497 |
530 |
name = StringUtils.replace(name, "MGI_M", "MGI Austria M"); //"MGI_M" --> "MGI / Austria M"
|
|
531 |
name = StringUtils.replace(name, "New_Brunswick_Stereographic", "New Brunswick Stereographic (ATS77)");
|
498 |
532 |
name = StringUtils.replace(name, "Lisboa", "Lisbon");
|
|
533 |
name = StringUtils.replace(name, "Lisbon_Lisbon", "Lisbon (Lisbon)");
|
|
534 |
name = StringUtils.replace(name, "Oslo_Norway", "(Oslo) NGO");
|
499 |
535 |
name = StringUtils.replace(name, "_", " ");
|
500 |
536 |
name = StringUtils.lowerCase(name);
|
501 |
537 |
return name;
|