wiki:CodeSnippets

Version 13 (modified by jng, 16 years ago) ( diff )

--

Introduction

This is a central location for users to share useful code snippets for FDO. Make sure that you read the FDO Cookbook chapter of the FDO Developers Guide as well.

Snippets

Eventually, we'll add categories to these. For now, just pick the one you're interested in...

Creating New Snippets

These code snippets are a community resource. You can use them in your work, but if you come up with something that seems like it should be easy but took you a while to figure it out, please add it here. Other developers are probably running into the same problem.

Account Requirements

Anyone with a valid OSGeo Userid may contribute and enhance community code snippets. Get involved and have fun!

Page Title

When creating a new page, please use the following convention for the page location:

CodeSnippets/YourPageName

for example: CodeSnippets/AJAXViewerEventHooking

This is to ensure that pages are easily found via the TitleIndex, and may allow for an automated index at some point.

You can easily do this by editing this CodeSnippets page, copying another entry, and then modifying it to fit your title. Once you have saved the page, you will have a handy link to follow to edit your own snippet.

Header Section

Please include the following on every Code Snippet page. It allows users to easily navigate the page, and if they come from a search engine they can get to the snippets index more easily. For an easier approach, download the plain text version of any existing Code Snippet (see the bottom of each page) to start from.

[[PageOutline]]

This page is an FDO Code Snippet.  Visit the CodeSnippets page to view more!

Syntax Highlighting

Trac has some really cool syntax highlighting built into it. The FDO Trac doesn't have all of these set up, but at least the C++ one works (add #!cpp to the top of your code block), and does a reasonable job with typical FDO code highlighting. For example:

  while (reader.ReadNext()) {
    extentAsByteArr = reader.GetExtent();
    // if extent type is dynamic and no geometries have been added
    // the extent can be null
    if (extentAsByteArr != null)
    {
      geom = geomFactory.CreateGeometryFromFgf(extentAsByteArr);
      extentAsText = geom.Text;
    }
    else
    {
      extentAsText = "No extent found";
    }
  }

Please use this where possible to make your inline examples more readable.

Conventions and Tips

  • For a jump-start, just download the plain text version of any existing Code Snippet (see the bottom of each page) and paste your modified version into a new page.
  • Try to provide both C++ and C# examples of your snippets if possible
  • Use two-space indents, and indent your entire code block by two spaces for enhanced readability.
  • Use inline comments heavily so that new users will understand what you are doing
  • If you want, you can add a Contributors section to your snippet for a little bit of fame.
Note: See TracWiki for help on using the wiki.