Changeset 28696 in osm for applications/editors/josm/plugins/opendata/modules/fr.toulouse
- Timestamp:
- 2012-09-08T19:09:04+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/opendata/modules/fr.toulouse
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/modules/fr.toulouse/build.xml
r28000 r28696 30 30 <property name="plugin.dist.dir" value="../../../../dist"/> 31 31 <property name="opendata" location="${plugin.dist.dir}/opendata.jar"/> 32 <property name="utilsplugin2" location="${plugin.dist.dir}/utilsplugin2.jar"/> 32 33 <property name="module.build.dir" value="build"/> 33 34 <property name="module.src.dir" value="src"/> … … 64 65 <pathelement location="${josm}"/> 65 66 <pathelement location="${opendata}"/> 67 <pathelement location="${utilsplugin2}"/> 66 68 </classpath> 67 69 <compilerarg value="-Xlint:deprecation"/> -
applications/editors/josm/plugins/opendata/modules/fr.toulouse/src/org/openstreetmap/josm/plugins/opendata/modules/fr/toulouse/ToulouseModule.java
r28554 r28696 16 16 package org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse; 17 17 18 import java.util.Collection; 19 import java.util.Comparator; 20 import java.util.TreeSet; 21 22 import org.openstreetmap.josm.Main; 23 import org.openstreetmap.josm.data.osm.DataSet; 24 import org.openstreetmap.josm.data.osm.Relation; 25 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 26 import org.openstreetmap.josm.io.OsmTransferException; 27 import org.openstreetmap.josm.plugins.opendata.core.io.NetworkReader; 18 28 import org.openstreetmap.josm.plugins.opendata.core.modules.AbstractModule; 19 29 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation; 30 import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.datasets.ToulouseDataSetHandler; 20 31 import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.datasets.associations.Club3eAgeHandler; 21 32 import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.datasets.citoyennete.BureauxVoteHandler; … … 102 113 handlers.add(InstallationSportiveToulouseHandler.class); 103 114 } 115 116 public static final DataSet data = new DataSet(); 117 118 private static final Collection<Relation> getBoundaries(int admin_level) { 119 Collection<Relation> result = new TreeSet<Relation>(new Comparator<Relation>() { 120 @Override 121 public int compare(Relation o1, Relation o2) { 122 return o1.get("ref").compareTo(o2.get("ref")); 123 } 124 }); 125 synchronized (data) { 126 for (Relation r : data.getRelations()) { 127 if (r.hasTag("admin_level", Integer.toString(admin_level)) && 128 (r.hasKey("name") || r.hasKey("ref") || r.hasKey("description"))) { 129 result.add(r); 130 } 131 } 132 } 133 return result; 134 } 135 136 public static final void downloadData() { 137 synchronized (data) { 138 if (data.allPrimitives().isEmpty()) { 139 for (final ToulouseDataSetHandler handler : new ToulouseDataSetHandler[]{ 140 new SecteursHandler(), new QuartiersHandler()}) { 141 Main.worker.submit(new Runnable() { 142 @Override 143 public void run() { 144 try { 145 DataSet ds = new NetworkReader(handler.getDataURL().toString(), handler, false). 146 parseOsm(NullProgressMonitor.INSTANCE); 147 handler.updateDataSet(ds); 148 synchronized (data) { 149 data.mergeFrom(ds); 150 } 151 } catch (OsmTransferException e) { 152 e.printStackTrace(); 153 } 154 } 155 }); 156 } 157 } 158 } 159 } 160 161 public static final Collection<Relation> getSectors() { 162 return getBoundaries(10); 163 } 164 165 public static final Collection<Relation> getNeighbourhoods() { 166 return getBoundaries(11); 167 } 104 168 } -
applications/editors/josm/plugins/opendata/modules/fr.toulouse/src/org/openstreetmap/josm/plugins/opendata/modules/fr/toulouse/datasets/ToulouseDataSetHandler.java
r28554 r28696 16 16 package org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.datasets; 17 17 18 import static org.openstreetmap.josm.tools.I18n.marktr; 19 import static org.openstreetmap.josm.tools.I18n.tr; 20 21 import java.awt.event.ActionEvent; 18 22 import java.net.MalformedURLException; 19 23 import java.util.Collection; 24 import java.util.Collections; 25 26 import org.openstreetmap.josm.Main; 27 import org.openstreetmap.josm.actions.JosmAction; 28 import org.openstreetmap.josm.data.osm.DataSet; 29 import org.openstreetmap.josm.data.osm.Node; 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 31 import org.openstreetmap.josm.data.osm.Relation; 20 32 import org.openstreetmap.josm.data.osm.Tag; 33 import org.openstreetmap.josm.data.osm.Way; 34 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 35 import org.openstreetmap.josm.data.osm.event.DataChangedEvent; 36 import org.openstreetmap.josm.data.osm.event.DataSetListener; 37 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent; 38 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent; 39 import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent; 40 import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent; 41 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 42 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 43 import org.openstreetmap.josm.plugins.opendata.OdPlugin; 21 44 import org.openstreetmap.josm.plugins.opendata.core.datasets.fr.FrenchDataSetHandler; 45 import org.openstreetmap.josm.plugins.opendata.core.layers.OdDataLayer; 22 46 import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.ToulouseConstants; 23 47 import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.ToulouseLicense; 48 import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.ToulouseModule; 49 import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils; 24 50 25 51 public abstract class ToulouseDataSetHandler extends FrenchDataSetHandler implements ToulouseConstants { … … 66 92 setDataURL(url+"/resource/document"); 67 93 } 94 addTool(new SplitBySector()); 95 addTool(new SplitByNeighbourhood()); 68 96 } catch (MalformedURLException e) { 69 97 e.printStackTrace(); … … 105 133 } 106 134 } 135 136 protected abstract class SplitAction extends JosmAction implements DataSetListener { 137 138 public SplitAction(String name, String desc) { 139 super(name, null, desc, null, false); 140 setEnabled(false); 141 ToulouseModule.data.addDataSetListener(this); 142 } 143 144 protected abstract Collection<Relation> getBoundaries(); 145 146 @Override 147 public void actionPerformed(ActionEvent e) { 148 final String baseName = OdPlugin.getInstance().getDialog().getDataLayer().getName(); 149 final DataSet baseDs = getCurrentDataSet(); 150 for (OsmPrimitive boundary : getBoundaries()) { 151 DataSet data = new DataSet(); 152 for (OsmPrimitive p : NodeWayUtils.selectAllInside(Collections.singleton(boundary), baseDs)) { 153 if (p instanceof Node) { 154 data.addPrimitive(new Node((Node)p)); 155 } else if (p instanceof Way) { 156 data.addPrimitive(new Way((Way)p)); 157 } else if (p instanceof Relation) { 158 data.addPrimitive(new Relation((Relation)p)); 159 } 160 } 161 Main.main.addLayer(new OdDataLayer(data, baseName+"/"+boundary.get("ref"), null, ToulouseDataSetHandler.this)); 162 } 163 } 164 @Override 165 public void dataChanged(DataChangedEvent event) { 166 setEnabled(!getBoundaries().isEmpty()); 167 } 168 @Override 169 public void primitivesAdded(PrimitivesAddedEvent event) { 170 } 171 @Override 172 public void primitivesRemoved(PrimitivesRemovedEvent event) { 173 } 174 @Override 175 public void tagsChanged(TagsChangedEvent event) { 176 } 177 @Override 178 public void nodeMoved(NodeMovedEvent event) { 179 } 180 @Override 181 public void wayNodesChanged(WayNodesChangedEvent event) { 182 } 183 @Override 184 public void relationMembersChanged(RelationMembersChangedEvent event) { 185 } 186 @Override 187 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 188 } 189 } 190 191 protected class SplitBySector extends SplitAction { 192 public SplitBySector() { 193 super(marktr("Split by sector"), tr("Split this data by sector (admin_level=10).")); 194 } 195 @Override 196 protected Collection<Relation> getBoundaries() { 197 return ToulouseModule.getSectors(); 198 } 199 } 200 201 protected class SplitByNeighbourhood extends SplitAction { 202 public SplitByNeighbourhood() { 203 super(marktr("Split by neighbourhood"), tr("Split this data by neighbourhood (admin_level=11).")); 204 } 205 @Override 206 protected Collection<Relation> getBoundaries() { 207 return ToulouseModule.getNeighbourhoods(); 208 } 209 } 210 211 @Override 212 public void notifyActive() { 213 ToulouseModule.downloadData(); 214 } 107 215 }
Note:
See TracChangeset
for help on using the changeset viewer.