I have a Shapefile map of Maryland separated by zipcode. What I'd like to do is color each area based on a value I'm looking up in a database. Currently, I'm using ASP.NET with the SharpMap package. The basic questions are:
1) How do I associate a shape with its zipcode? I can generate the list of zipcodes using SharpMap's ExecuteIntersectionQuery with the BoundingBox set as the extent of the map, but I have no idea how to then connect each row of the resulting table with the shape it represents.
2) Once I have access to an individual shape and know what color I want, how do I assign the color to the shape? In SharpMap, I can color a VectorLayer, but a VectorLayer is generated from a source .shp file, not a shape.
I'm open to using other free map packages besides SharpMap (so no ArcGIS), but for legal reasons I can't use GoogleMaps.
I feel like this should be relatively simple, but trying to find any decent resource for SharpMap is pretty difficult.
EDIT: Alright, I've made a lot of process just by reading over what documentation there is. By setting the FilterDelegate of ShapeFile, I can make a layer consist of only the rows where the zip code matches a certain value. Now my only problem is making the delegate filter look for a different zip code each time. Can I pass another parameter besides the FeatureDataRow? Should I resort to a global variable?
You'll need to use thematics to do this.
I'll assume you already have some code that configures your map and it's layers. Your shapefile is a VectorLayer.
VectorLayer shapefileLayer = GetMyShapefileLayer();
shapefileLayer.Theme = new SharpMap.Rendering.Thematics.CustomTheme(GetStyleForShape);
Then, method GetStyleForShape is called every time the map needs a style for rendering. It looks like this:-
private SharpMap.Styles.VectorStyle GetStyleForShape(SharpMap.Data.FeatureDataRow row, SharpMap.Layers.Layer layer)
{
}
In the method, you create and return a VectorStyle. The table data associated with the feature it's trying to render is passed as a parameter to this method.
So you can use the row parameter to get your zip code, do whatever logic you need to do to calculate it's style, configure that style and return it.
This method (potentially) gets called a lot, so consider storing the styles and reusing them, rather than recreating them every time.
Hope this helps.
Related
I am using HoloViews version 1.12.0 . I am attempting to create a layout that contains two DynamicMaps, but I am getting the error:
WARNING:param.Warning: Layout contains HoloMaps which are not nested in the recommended format for accessing your data; calling .collate() on these objects will resolve any violations of the recommended nesting presented in the Composing Data tutorial ...
One of the DynamicMaps itself contains a layout that consists of a Radial Heat Map, and a Div. The other DynamicMap contains a Table object. The idea is to add some additional DynamicMaps to the layout, such that there are streams creating click through parent child relationship between the DynamicMaps.
I have run the .collate() function on both of the DynamicMaps, but it didn't return any output, and the error persists.
If I alter the one DynamicMap that contains the layout of the div and radial heat map, to just containing the one object or the other, the issue goes away.
Here is the data structures output for my layout.
:Layout
.DynamicMap.I :DynamicMap [ownership,survey_type,rep,approval,timeframe,nps_type]
.DynamicMap.II :DynamicMap [ownership,survey_type,rep,approval,timeframe,nps_type]
The http://holoviews.org/user_guide/Building_Composite_Objects.html user guide explains the order things need to be nested to work smoothly without collate:
A DynamicMap normally takes the same spot as a HoloMap in such a hierarchy.
I'm surprised that .collate() "didn't return any output", though; I don't think there is any version of .collate() in HoloViews that doesn't return something, so there's presumably some other problem.
I would like to know if there is a way to inject a predefine layout in Vis.
I managed to save all coordinate of my nodes (X : Y) when i drag an drop each node, which is then saved to the database with a specified ID for each nodes.
What i struggle with is to specified this dataset to vis when i initialize a map with vis ( here is the doc of layout initilisation : http://visjs.org/docs/network/layout.html#)
i would like to put an array with my id nodes and position X Y so that it get saved when user change their layout.
It appears that it is not possible, but maybe there is a hidden way ?
Thanks in advance
This is quite possible:
to set initial layout, just add coordinates to each node (and disable physics so that they don't flow away from their positions):
nodes = [{id:1, label:'some', x:100, y:0 }, ... ];
options = { physics: false, ... };
to get current coordinates, use network.getPositions()
to save those at layout change, you probably want to use the dragEnd event and the on method (use network.getPositions() inside the event handler)
You can opt my implementation in the VisGraphPlugin repo (it's a plugin for TiddlyWiki Classic), just look for dragEnd and saveDataAndOptions, the latter may be of interest.
Instead of saving positions and id's you can simply use getSeed() method to save your layout configuration in a seed. Then, when you start the network again you can load this seed into the layout.randomSeed to have the same configuration.
The documentation for getSeed() says:
If you like the layout of your network and would like it to start in the same way next time, ask for the seed using this method and put it in the layout.randomSeed option.
I don't know how to get sprites to stick to each other so they become one big object instead of tiny little pieces, for example:
attaching a thruster to a box, then the thruster stays in that spot while pushing the box, and also is there a certain term for what I'm talking about?
You could also attach all parts to one of the objects, it would sort of look like:
//Main object
x = 5;
y = 20;
//other object step event
x = obj_main.x + <any value to put it where you want>;
y = obj_main.y + <any value to put it where you want>;
//This will force the parts to follow the main object.
`
`
You can use an array, defined in the 'main' object to use a sort of grid to define where each piece is and then either draw each individual sprite, based on its position in the array, originating from the 'main' object's coordinates. Or just create an individual instance of an object if you would like to have additional functionality by trading off some performance.
For more information on arrays and how to position sprites and objects based on set coordinates, check out the GML documentation provided below:
Arrays:
https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/401_06_arrays.html
lengthdir:
https://docs.yoyogames.com/source/dadiospice/002_reference/maths/real%20valued%20functions/lengthdir_x.html
what I did was make the object disabled, so when I press left and right it doesn't go anywhere, only the other piece would move, but when it came into contact it allowed the other piece to move along with it, and set its speed to the corresponding objects speed, in simpler term, when I collide with it, it turns the movement on and goes in the same direction as the current object in the same speed, making it look like its sticking
I am trying to render a whole heap of vectors in the google earth plugin. I use the parseKml method to create my Kml Feature object and store it in an array. The code looks something like below. I loop over a list of 10,000 kml objects that I return from a database and draw it in the plugin.
// 'currentKml' is a kml string returned from my DB.
// I iterate over 10,000 of these
currentKmlObject = ge.parseKml(currentKml);
currentKmlObject.setStyleSelector(gex.dom.buildStyle({
line: { width: 8, color: '7fff0000' }
}));
ge.getFeatures().appendChild(currentKmlObject);
// After this, I store teh currentKml object in an array so
// I can manipulate the individual features.
This seems to work fine. But when I want to turn the visibility of all these features on or off at once, I have to iterate over all of these kml objects in my array and set their individual visibilities on or off. This is a bit slow. If I am zoomed out, I can slowly see each of the lines disappearing and it takes about 5 - 10 seconds for all of them to disappear or come back.
I was wondering if I could speed up this process by adding a layer and adding all my objects as children of this layer. This way I set the visibility of the whole layer on or off.
I have been unable to find out how to create a new layer in code though. If someone can point the appropriate methods, it would be great. I am not sure if a layer is the right approach to speed up the process either. If you also have any other suggestions on how I can speed up the process of turning on/off all these objects in the map at once, that would be very helpful as well.
Thanks in advance for you help.
Ok, found out how to do this by myself.
In the google earth extensions libarary I use the 'buildFolder' method.
var folder = gex.dom.buildFolder({ name: folderName });
ge.getFeatures().appendChild(folder);
Now, when I iterate over my object array, I add them to the folder instead using the following
folder.getFeatures().appendChild(currentKmlObject);
This way, later on I can turn the visibility on and off at the folder level using
folder.setVisibility(false); // or true
And this works quite well as well. IThere is no delay, I can see all the objects turning on and off at once. It is quite quick and performant.
In the Flash authoring environment I can edit a library symbol and all on-stage instances based upon it reflect the changes. How can I do the same thing in ActionScript? There seems to be no way to address a library symbol.
For example:
Inside Flash CS3, I have created a Square.swf file that has 100 instances of the library symbol Square.
Now, Square.swf is loaded into another file BlueSquare.swf and I want to change the Square symbol into a blue square so that all instances of Square become blue.
How do I do this using Actionscript?
Thanks for the help.
What's in a clip's library symbol is the author-time definition of that object - you can't change it at runtime. Instead the normal approach would be to dynamically change the contents (not definitions) of the clips you want to change, which can be done in various ways, but all the good ways of doing that involve making the dynamically-changing clip understand how to update its appearance. So you need to be able to re-author the changing clips to suit your needs.
If you're loading in an animation that somebody else made, and trying to go through and replace all instances of object A with object B, the only way to achieve that is to traverse through the content's display list looking for A, and when you find one, remove its children and replace them with the the contents of a B. Mind you, for animations that may not really solve your problem, since animations normally add and remove clips frequently, so at any given point you could replace all the "hand" clips with "hand2", but then a frame later new "hand" clips might come into existence. But short of opening up the SWF and changing the binary data inside, there's no other way to dynamically change all of a given object to something else unless the object knows how to change its contents.
If it is only about making sure that the square you are attaching is blue you could use the colorTransform to change its appearance:
var someSquare:Square = new Square();
someSquare.transform.colorTransform = new ColorTransform(0,0,0,1,0x00,0x00,0xff,0x00 );
addChild( someSquare );
Of course this does not change the color of all instances that you have already attached.
If you really wanted to change the actual SWF symbol in Actionscript the only way I see is to parse the swf with as3swf ( https://github.com/claus/as3swf/wiki ), find the shape tag of the symbol, change it and then load the ByteArray that contains the swf via loader.loadBytes() - but that's admittedly quite a complicated way and you can achieve the same result by simply putting some colorizing code into the shape symbol itself and then trigger the color change via an Event that is broadcasted by your main app.
Of course, if you make custom component, when you change it changes will appear on all instances of that component/class. Here's the example: http://livedocs.adobe.com/flex/3/html/intro_3.html
On the other hand, if you use modules whey pretty much do the same as swf-s you used in Flash, when you rebuild-recompile them changes will reflect on your main application which uses them. Here's th eexample for modules: http://blog.flexexamples.com/2007/08/06/building-a-simple-flex-module/
So MXML/AS component/class are your "symbols" which you can create or drop on stage on fly.
Modules are "movies" you can load and they run on their own with possibility to communicate to main movie.
The closest way of achieving this is to use Bitmaps. If you update the bitmapData they display, they will all update automatically.
However this approach is not good at all. You should maintain application state separately in an object model, and have the visualisation update, if the state changes.
What you want to do, is to misuse a feature for changing graphic appearence at design time, to change application state at runtime. In generally, ideas like these can be thought off as bad.
For example if you take the time to separate the state model and the visualisation layer, it will become fairly easy to save the game state on a server or to synchronize it with other clients to achieve multiuser features.
greetz
back2dos
If you are trying to build an Avatar and user can customize your Avatar parts e.g. hands, legs, face etc. and you want all these assets to be kept in separate swf file, that is pretty straightforward. You keep all the assets, in separate swf or one large swf file and load them at runtime. Now, maintain your Avatar object instance and place the child objects, which are chosen by the user.
You can create inside your class a static List with references all the created instances and then apply a change with static methods. For example:
package
{
import flash.display.MovieClip;
import flash.geom.ColorTransform;
public class Square extends MovieClip
{
public static var instances:Array = new Array();
public function Square():void
{
Square.instances.push(this); // This is the trick. Every time a square is created, it's inserted in the static list.
}
// This property gets the color of the current object (that will be the same of all others because the setter defined below).
public function get color():ColorTransform
{
return this.transform.colorTransform;
}
public function set color(arg:ColorTransform):void
{
// Sets the color transform of all Square instances created.
for each(var sqr:Square in Square.instances)
{
sqr.transform.colorTransform = arg;
}
}
}
}