Skip to content

Commit

Permalink
from 500 to 10,000 points
Browse files Browse the repository at this point in the history
  • Loading branch information
mapmeld committed Apr 27, 2012
1 parent 8950000 commit 0329fcc
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
83 changes: 83 additions & 0 deletions Datasource.server.bones
@@ -0,0 +1,83 @@
var path = require('path');
var url = require('url');
var fs = require('fs');
var mapnik = require('mapnik');
var Step = require('step');
var millstone = require('millstone');

models.Datasource.prototype.sync = function(method, model, success, error) {
if (method !== 'read') return error('Method not supported.');

var options = model.options;
var config = Bones.plugin.config;

if (!options) return error(new Error('options are required.'));
if (!options.id) return error(new Error('id is required.'));
if (!options.project) return error(new Error('project is required.'));

millstone.resolve({
mml: {
Stylesheet: [{ id: 'layer', data: '' }],
Layer: [{
name: options.id,
srs: options.srs || '',
Datasource: options
}]
},
base: path.join(config.files, 'project', options.project),
cache: path.join(config.files, 'cache')
}, function(err, mml) {
if (err) return error(err);

try {
mml.Layer[0].Datasource = _(mml.Layer[0].Datasource).defaults(options);

// Some mapnik datasource accept 'row_limit` (like postgis, shape)
// those that do not will be restricted during the featureset loop below
var row_limit = 10000;
//mml.Layer[0].Datasource = _(mml.Layer[0].Datasource).defaults({row_limit:row_limit});
//console.log(mml.Layer[0].Datasource);
var source = new mapnik.Datasource(mml.Layer[0].Datasource);

var features = [];
if (options.features || options.info) {
var featureset = source.featureset();
for (var i = 0, feat;
i < row_limit && (feat = featureset.next(true));
i++) {
features.push(feat.attributes());
}
}

var desc = source.describe();
var datasource = {
id: options.id,
project: options.project,
url: options.file,
fields: desc.fields,
features: options.features ? features : [],
type: desc.type,
geometry_type: desc.type === 'raster' ? 'raster' : desc.geometry_type
};

// Process fields and calculate min/max values.
for (var f in datasource.fields) {
var values = _(features).pluck(f);
var type = datasource.fields[f];
datasource.fields[f] = { type: type };
if (options.features || options.info) {
datasource.fields[f].max = type === 'String'
? _(values).max(function(v) { return (v||'').length })
: _(values).max();
datasource.fields[f].min = type === 'String'
? _(values).min(function(v) { return (v||'').length })
: _(values).min();
}
}
} catch(err) {
return error(err);
}

success(datasource);
});
};
7 changes: 5 additions & 2 deletions readme.md
Expand Up @@ -5,9 +5,12 @@ Works with CSV files from <a href="http://geocommons.com">GeoCommons</a>, the EP
Works with any layer that includes attributes for latitude and longitude ( they can have any name, but they must appear in the layer inspector view )

<h3>Install</h3>
Mac OS X Terminal one-liner:
Mac OS X Terminal - install plugin:
<code>cp -r TileMill-GeoCSV /Applications/TileMill.app/Contents/Resources/plugins/</code>

For layers with more than 500 points, copy this to raise max to 10,000 points
<code>cp TileMill-GeoCSV/Datasource.server.bones /Applications/TileMill.app/Contents/Resources/models/

<h3>What to do</h3>
<ol>
<li>Open the new GeoCSV plugin (it looks like a dot).</li>
Expand Down Expand Up @@ -52,4 +55,4 @@ TODO: combine rules such as [ far LAT, LNG, DEGREES ] [ far LAT, LNG, DEGREES ]
<li>Re-style densely-packed points to make them more distinct</li>
<li>Map toxic sites within your city limits</li>
<li>Contrast points within and outside of a business/delivery service area</li>
</ul>
</ul>

0 comments on commit 0329fcc

Please sign in to comment.