Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply code-formatter in module 'org.locationtech.udig.render.wms.basic' #543

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ build.xml
workspace
runtime-udig.product
.sts4-cache/
docs/__pycache__
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
/**
* uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -31,88 +31,93 @@

/**
* Creates Metrics for the BasicWMSRenderer
*
*
* @author Richard Gould
*/
public class BasicWMSMetricsFactory2 implements IRenderMetricsFactory {

Map<String, CoordinateReferenceSystem> crsCache=new HashMap<String, CoordinateReferenceSystem>();
Map<Pair,MathTransform> transformCache=new HashMap<Pair, MathTransform>();
Map<Layer, Set<CoordinateReferenceSystem>> legalCRSCache=new HashMap<Layer, Set<CoordinateReferenceSystem>>();

public boolean canRender( IRenderContext toolkit ) {
if( !toolkit.getLayer().hasResource(WebMapServer.class) ) {
return false; // not a wms
Map<String, CoordinateReferenceSystem> crsCache = new HashMap<>();

Map<Pair, MathTransform> transformCache = new HashMap<>();

Map<Layer, Set<CoordinateReferenceSystem>> legalCRSCache = new HashMap<>();

@Override
public boolean canRender(IRenderContext toolkit) {
if (!toolkit.getLayer().hasResource(WebMapServer.class)) {
return false; // not a WMS
}
CoordinateReferenceSystem crs = toolkit.getViewportModel().getCRS();
if( crs == null ) {
return true; // we will assume our default
}
if (crs == null) {
return true; // we will assume our default
}
org.geotools.ows.wms.Layer layer;
try {
layer = toolkit.getLayer().getResource(org.geotools.ows.wms.Layer.class, null);
} catch (IOException e) {
return false;
}
if( layer == null ){
if (layer == null) {
return false;
}
Set<CoordinateReferenceSystem> crss = legalCRSCache.get(layer);
if( crss!=null && crss.contains(crs))
if (crss != null && crss.contains(crs))
return true;
if( searchForCRSMatch(crs, layer) ){
if( crss==null ){
crss=new HashSet<CoordinateReferenceSystem>();
if (searchForCRSMatch(crs, layer)) {
if (crss == null) {
crss = new HashSet<>();
legalCRSCache.put(layer, crss);
}
crss.add(crs);

return true;
}
return false;
}

private boolean searchForCRSMatch( CoordinateReferenceSystem crs, org.geotools.ows.wms.Layer layer ) {
Set srs = layer.getSrs();
for( Iterator i=srs.iterator(); i.hasNext();) {
private boolean searchForCRSMatch(CoordinateReferenceSystem crs,
org.geotools.ows.wms.Layer layer) {
Set srs = layer.getSrs();
for (Iterator i = srs.iterator(); i.hasNext();) {
try {
String epsgCode = (String) i.next();
CoordinateReferenceSystem rs = getCRS(epsgCode);

if (rs.equals(crs)) {
return true;
}

MathTransform transform = getMathTransform(crs, rs);

if (transform != null) {
return true;
}
}
catch( Throwable t ) {
// could not create a object representation of this code
} catch (Throwable t) {
// could not create a object representation of this code
}
}
return false; // we cannot handle crs
return false; // we cannot handle CRS
}

private synchronized MathTransform getMathTransform( CoordinateReferenceSystem from, CoordinateReferenceSystem to) throws FactoryException {
Pair pair = new Pair(from,to);
MathTransform result=this.transformCache.get(pair);
if( result==null ){
result=CRS.findMathTransform(from, to, true);
private synchronized MathTransform getMathTransform(CoordinateReferenceSystem from,
CoordinateReferenceSystem to) throws FactoryException {
Pair pair = new Pair(from, to);
MathTransform result = this.transformCache.get(pair);
if (result == null) {
result = CRS.findMathTransform(from, to, true);
transformCache.put(pair, result);
}
return result;
}

private synchronized CoordinateReferenceSystem getCRS( String epsgCode ) throws NoSuchAuthorityCodeException {
private synchronized CoordinateReferenceSystem getCRS(String epsgCode)
throws NoSuchAuthorityCodeException {
CoordinateReferenceSystem result = crsCache.get(epsgCode);
if( result==null ){
if (result == null) {
try {
result=CRS.decode( epsgCode );
result = CRS.decode(epsgCode);
} catch (FactoryException e) {
throw (RuntimeException) new RuntimeException( ).initCause( e );
throw (RuntimeException) new RuntimeException().initCause(e);
}
crsCache.put(epsgCode, result);
}
Expand All @@ -122,20 +127,23 @@ private synchronized CoordinateReferenceSystem getCRS( String epsgCode ) throws
/**
* @see org.locationtech.udig.project.render.RenderMetricsFactory#createMetrics(org.locationtech.udig.project.render.RenderContext)
*/
public AbstractRenderMetrics createMetrics( IRenderContext context ) {
@Override
public AbstractRenderMetrics createMetrics(IRenderContext context) {
return new BasicWMSMetrics2(context, this);
}

/**
* @see org.locationtech.udig.project.render.RenderMetrics#getRendererType()
*/
@Override
public Class getRendererType() {
return BasicWMSRenderer2.class;
}

private class Pair{
final CoordinateReferenceSystem from,to;
private class Pair {
final CoordinateReferenceSystem from, to;

public Pair( CoordinateReferenceSystem from, CoordinateReferenceSystem to ) {
public Pair(CoordinateReferenceSystem from, CoordinateReferenceSystem to) {
this.from = from;
this.to = to;
}
Expand All @@ -150,7 +158,7 @@ public int hashCode() {
}

@Override
public boolean equals( Object obj ) {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
Expand Down
Loading